本文介绍了Android的搜索查看X标记的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想改变我可以改变它在搜索视图component.How显示白色绘制X标记。请帮助我。谢谢。
SearchManager searchManager =(SearchManager)getSystemService(Context.SEARCH_SERVICE);
搜索查看=(搜索查看)menu.findItem(R.id.ac_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(真正的);
尝试{
现场searchField = SearchView.class.getDeclaredField(mSearchButton);
searchField.setAccessible(真正的);
ImageView的searchBtn =(ImageView的)searchField.get(搜索查看);
searchBtn.setImageResource(R.drawable.ac_search);
searchField = SearchView.class.getDeclaredField(mSearchPlate);
searchField.setAccessible(真正的);
的LinearLayout searchPlate =(的LinearLayout)searchField.get(搜索查看);
searchPlate.setBackgroundResource(R.drawable.search_edit_text_holo_light);
AutoCompleteTextView searchText =(AutoCompleteTextView)searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources()的getColor(android.R.color.white));
searchText.setHint(R.string.ac_search_here);
searchText.setTextColor(getResources()的getColor(android.R.color.white));
}赶上(NoSuchFieldException E){}赶上(IllegalAccessException E){}
解决方案
查看关闭= searchPlate.findViewById(R.id.search_close_btn);
close.setBackgroundResource(R.drawable.selectable_background_orange);
或设置样式searchViewCloseIcon:
<项目名称=机器人:searchViewCloseIcon> @可绘制/ ic_close< /项目>
<项目名称=searchViewCloseIcon> @可绘制/ ic_close< /项目> (支持库)
I want to change X mark in white color drawable displayed in search view component.How can I change it.please help me.thanks.
SearchManager searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView)menu.findItem(R.id.ac_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true);
try{
Field searchField = SearchView.class.getDeclaredField("mSearchButton");
searchField.setAccessible(true);
ImageView searchBtn = (ImageView)searchField.get(searchView);
searchBtn.setImageResource(R.drawable.ac_search);
searchField = SearchView.class.getDeclaredField("mSearchPlate");
searchField.setAccessible(true);
LinearLayout searchPlate = (LinearLayout)searchField.get(searchView);
searchPlate.setBackgroundResource(R.drawable.search_edit_text_holo_light);
AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(android.R.color.white));
searchText.setHint(R.string.ac_search_here);
searchText.setTextColor(getResources().getColor(android.R.color.white));
}catch (NoSuchFieldException e){}catch (IllegalAccessException e){}
解决方案
View close = searchPlate.findViewById(R.id.search_close_btn);
close.setBackgroundResource(R.drawable.selectable_background_orange);
or set style for searchViewCloseIcon :
<item name="android:searchViewCloseIcon">@drawable/ic_close</item>
<item name="searchViewCloseIcon">@drawable/ic_close</item> (Support Library)
这篇关于Android的搜索查看X标记的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!