How to remove white underline in a SearchView widget in Toolbar Android -
i using toolbar search widget in project. works fine expect thing stuck removing underline below search field in toolbar. have tried many solutions , nothing works out. below of solutions tried.
requirement remove white underline in image

ist solution:
//removing underline int searchplateid = searchview.getcontext().getresources().getidentifier("android:id/search_plate", null, null); view searchplate = searchview.findviewbyid(searchplateid); if (searchplate!=null) { searchplate.setbackgroundcolor (color.transparent); int searchtextid = searchplate.getcontext ().getresources ().getidentifier ("android:id/search_src_text", null, null); } iind solution:
edittext searchedit = ((edittext)searchview.findviewbyid(android.support.v7.appcompat.r.id.search_src_text)); searchedit.setbackgroundcolor(color.transparent); the above code works change background of edittext still underline displaying below close icon in searchbar.
complete code using searchbar widget follows:
@override public void oncreateoptionsmenu(menu menu, menuinflater infl) { super.oncreateoptionsmenu(menu, infl); menuinflater inflater = getactivity().getmenuinflater(); inflater.inflate(r.menu.action_search, menu); final searchview searchview = (searchview) menuitemcompat .getactionview(menu.finditem(r.id.search)); searchmanager searchmanager = (searchmanager) getactivity ().getsystemservice (getactivity ().search_service); searchview.setsearchableinfo (searchmanager.getsearchableinfo (getactivity ().getcomponentname ())); //changing edittext color edittext searchedit = ((edittext)searchview.findviewbyid(android.support.v7.appcompat.r.id.search_src_text)); searchedit.settextcolor(color.white); } action_search.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:compat="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/search" android:title="search" android:icon="@drawable/abc_ic_search_api_mtrl_alpha" compat:showasaction="ifroom|collapseactionview" compat:actionviewclass="android.support.v7.widget.searchview" /> </menu> possible duplicate of this
thanks in advance, kind of solutions , suggestions useful me.
once try follows
view v = searchview.findviewbyid(android.support.v7.appcompat.r.id.search_plate); v.setbackgroundcolor(color.parsecolor("here give actionbar color code")); hope helps you.
Comments
Post a Comment