Customize the searchview editing box, search button, delete button, and cursor

Source: Internet
Author: User

 
It is useless to say more, and you can directly use the code.
<PRE name = "code" class = "Java"> <span style = "white-space: pre"> </span> class <?> Argclass = msearchview. getclass (); // specify a private attribute field 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 msearchplate is statelistdrawable (images in different States). Therefore, bitmapdrawable field ownfield = argclass cannot be used. getdeclaredfield ("msearchplate"); // setaccessible is used to set whether the private attribute in the reflection class has the permission. It can be accessed only when it is set to true. The default value is false ownfield. setaccessible (true); view mview = (View) ownfield. get (msearchview); mview. setbackground (getresources (). getdrawable (R. drawable. person_edittext_selector ));


 
<PRE name = "code" class = "Java"> <span style = "white-space: pre"> </span> // modify the close icon field mclosebutton = argclass. getdeclaredfield ("mclosebutton"); mclosebutton. setaccessible (true); imageview backview = (imageview) mclosebutton. get (msearchview); backview. setimageresource (R. drawable. delete_selector); // modify it to the search icon field msearchbutton = argclass. getdeclaredfield ("msearchbutton"); msearchbutton. setaccessibl E (true); imageview search = (imageview) msearchbutton. get (msearchview); search. setimageresource (R. drawable. main_search_selector); // modify the cursor // specify a private attribute field mquerytextview = argclass. getdeclaredfield ("mquerytextview"); mquerytextview. setaccessible (true); Class <?> Mtextviewclass = mquerytextview. get (msearchview ). getclass (). getsuperclass (). getsuperclass (). getsuperclass (); // mcursordrawableres the attribute of the cursor image ID. This attribute is the property of textview. Therefore, the parent class of the autocompletetextview (searchautocomplete) // is used) field mcursordrawableres = mtextviewclass. getdeclaredfield ("mcursordrawableres"); // setaccessible is used to set whether the private attribute in the reflection class has the permission. It can be accessed only when it is set to true. The default value is false MC. Ursordrawableres. setaccessible (true); // note that the cursor of the object (msearchview) holding this attribute (mquerytextview) must be an image rather than a color because the light is marked with two images, // One is the blinking image when the focus is obtained for the first time, and the other is the image with content at the back. If the color is filled, the flickering image will be lost, // color filling will shorten the distance between the text and the optical mark (some letters will be covered by the cursor ). Mcursordrawableres. Set (mquerytextview. Get (msearchview), R. drawable. divider_selector );


 
 
 
 

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.