How to remove white underline in a SearchView widget in Toolbar Android

后端 未结 10 2076
挽巷
挽巷 2020-12-01 03:33

I am using Toolbar search widget in my project. Everything works fine but expect the thing which I am completely stuck up with removing the underline below search field in m

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 03:52

    The code for changing the background color of SearchView edit text is below

    public static void setSearchViewEditTextBackgroundColor(Context context, SearchView searchView, int backgroundColor){
        int searchPlateId = context.getResources().getIdentifier("android:id/search_plate", null, null);
        ViewGroup viewGroup = (ViewGroup) searchView.findViewById(searchPlateId);
        viewGroup.setBackgroundColor(ComponentUtils.getColor(context, backgroundColor));
    }
    

    If your action bar background color is white then call the above method as follow.

    setSearchViewEditTextBackgroundColor(this, searchView, R.color.white);
    

    Now the underline from SearchView edit text will disappear.

提交回复
热议问题