Android actionBar searview changes default search button Image

Source: Internet
Author: User

Android actionBar searview changes default search button Image

When searching for images, it is found that the default search button displayed by the searchView system is only a small arrow, which looks ugly and wants to change this icon. So I found the answer on the stackoverflow website and directly wrote the code:

@ Override public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {inflater. inflate (R. menu. event_history, menu); MenuItem search = menu. findItem (R. id. search_event); search. collapseActionView (); // It is displayed in the search box by default. // search. expandActionView (); SearchView searchView = (SearchView) search. getActionView (); // display the search confirmation button searchView. setSubmitButtonEnabled (true); // find the LinearLayout int searchPlateId = searchView corresponding to the search button. getContext (). getResources (). getIdentifier ("android: id/submit_area", null, null); LinearLayout searchPlate = (LinearLayout) searchView. findViewById (searchPlateId); // get the image view of the search icon, so that you can modify the image (imageview) searchPlate. getChildAt (0 )). setImageResource (R. drawable. audio_bar_src); searchView. setOnQueryTextListener (this); super. onCreateOptionsMenu (menu, inflater );}


Related Article

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.