Custom Searchview edit box, search button, delete button, cursor etc.

Source: Internet
Author: User

  //Specify a private propertyField Msearchhinticonfield = Argclass.getdeclaredfield ("Msearchhinticon"); Msearchhinticonfield.setaccessible (true); ImageView Msearchhinticon= (ImageView) Msearchhinticonfield.Get(Msearchview); //msearchhinticon.setvisibility (View.gone); Msearchhinticon.setimageresource (R.drawable.main_search_selector); //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.person_edittext_selector)); 
Field Mclosebutton = Argclass.getdeclaredfield ("Mclosebutton"); Mclosebutton.setaccessible (true); ImageView Backview= (ImageView) Mclosebutton.Get(Msearchview);                            Backview.setimageresource (R.drawable.delete_selector); //Search icon when modified to expandField Msearchbutton = Argclass.getdeclaredfield ("Msearchbutton"); Msearchbutton.setaccessible (true); ImageView Search= (ImageView) Msearchbutton.Get(Msearchview);                           Search.setimageresource (R.drawable.main_search_selector); //Modify Cursor//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.divider_selector);

Custom Searchview edit box, search button, delete button, cursor etc.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.