Try{Class<?> argclass=Msearchview.getclass (); //Specify a private propertyField Msearchhinticonfield = Argclass.getdeclaredfield ("Msearchhinticon"); Msearchhinticonfield.setaccessible (true); View Msearchhinticon=(View) msearchhinticonfield.get (Msearchview); Msearchhinticon.setvisibility (View.gone); //Note that the background of the msearchplate is statelistdrawable (different states of the picture) so you can't use bitmapdrawableField Ownfield = Argclass.getdeclaredfield ("Msearchplate"); //setaccessible It is used to set whether there is permission to access private properties in the reflection class, only if set to true to be accessible, default to FalseOwnfield.setaccessible (true); View MView=(View) ownfield.get (Msearchview); Mview.setbackground (Getresources (). getdrawable (R.DRAWABLE.CONTACTS_SEARCH_WRITEBG)); //Specify a private propertyField Mquerytextview = Argclass.getdeclaredfield ("Mquerytextview"); Mquerytextview.setaccessible (true); Class<?> Mtextviewclass =Mquerytextview.get (Msearchview). GetClass (). Getsuperclass (). Getsuperclass (). Getsuperclass (); //Mcursordrawableres the property of the cursor picture ID is the property of the TextView, so use Mquerytextview (searchautocomplete)//The parent class (EditText) of the parent class (Autocompletetextview) ( TextView)Field mcursordrawableres = Mtextviewclass.getdeclaredfield ("Mcursordrawableres"); //setaccessible It is used to set whether there is permission to access private properties in the reflection class, only if set to true to be accessible, default to FalseMcursordrawableres.setaccessible (true); //Note that the first parameter holding this property (Mquerytextview) of the object (Msearchview) cursor must be a picture cannot be a color because the cursor has two pictures,//One is the first time to get the focus of the flashing picture, a picture behind the content, if filled with color, it will lose the flashing picture,//Color fills shorten the distance between the text and the cursor (some letters will cover a portion of the cursor). Mcursordrawableres.set (Mquerytextview.get (Msearchview), r.drawable.icon_small_add_delete); } Catch(Exception e) {e.printstacktrace (); }
Reference Original: http://blog.csdn.net/chenshijun0101/article/details/21521137
Android Searchview Style modification