1

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=" "
    />
Tom
  • 47
  • 6
  • That seems like elevation, have you tried that? – cutiko Apr 11 '20 at 18:30
  • Have not used any elevation. Added some to test and the see difference, and it was noticeably different than the line. – Tom Apr 11 '20 at 19:05
  • If you want to make characters which are searched colored, see my question and answer here: https://stackoverflow.com/questions/59628149/how-can-we-have-searched-characters-colored-when-we-use-searchview-in-recyclervi – MMG Apr 11 '20 at 19:07
  • Can you post a picture of the result? – Tom Apr 11 '20 at 19:25

4 Answers4

1

Try the following code:

View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
v.setBackgroundColor(Color.parseColor("here give actionbar color code"));
1

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);
Prashant.J
  • 739
  • 7
  • 12
1
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
View searchPlate = findViewById(searchPlateId);
searchPlate.setBackgroundResource(0);

This removes any type of background from the search plate.

Ankit Verma
  • 496
  • 5
  • 21
0

This is how it worked for me

val searchPlate = searchView.findViewById<View>(androidx.appcompat.R.id.search_plate)
searchPlate.setBackgroundResource(R.drawable.search_textfield_shape)
Jamal N
  • 351
  • 1
  • 6