Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

android - How to delete or change the searchview icon inside the SearchView actionBar?

screenshot

How to remove or change the search view icon inside the edittext? I am using the Appcompat library.

I used the below code to modify and remove but it's not working:

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    View search_mag_icon = (View)searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
        search_mag_icon.setBackgroundResource(R.drawable.ic_stub);
        //search_mag_icon.setVisibility(View.GONE);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Finally found the solution. Try the following:

try {
    Field mDrawable = SearchView.class.getDeclaredField("mSearchHintIcon");
    mDrawable.setAccessible(true);
    Drawable drawable =  (Drawable)mDrawable.get(your search view here);
    drawable.setAlpha(0);
} catch (Exception e) {
    e.printStackTrace();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...