Search code examples
androidandroid-layoutsearchviewunderline

How to remove underline on searchview with drawable background


Snapshot from emulator

How can i remove the underline as shown in the picture? Setting it to transparent or changing background does not help.

Already tried these solutions: How to remove white underline in a SearchView widget in Toolbar Android

Both changing style to actionbar-searchview and programmaticly. Problem with changing querybackground is that it will ignore the drawable background i have already set.

    <SearchView
    android:id="@+id/searchViewBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded_corner"
    android:focusable="true"
    android:queryHint=" "
    />

Solution

  • You need to change search_edit_frame, search_plate and search_bar where you have declared this view.

        int searchFrameId = searchView.getContext().getResources().getIdentifier("android:id/search_edit_frame", null, null);
    View searchFrame = searchView.findViewById(searchFrameId);
    searchFrame.setBackgroundResource(R.drawable.rounded_corner);
    
    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
    View searchPlate = findViewById(searchPlateId);
    searchPlate.setBackgroundResource(R.drawable.rounded_corner);
    
    int searchBarId = searchView.getContext().getResources().getIdentifier("android:id/search_bar", null, null);
    View searchBar = findViewById(searchBarId);
    searchBar.setBackgroundResource(R.drawable.rounded_corner);