gpt4 book ai didi

Android SearchView X 标记图标

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:39:02 27 4
gpt4 key购买 nike

enter image description here

我想更改搜索 View 组件中显示的白色可绘制对象中的 X 标记。如何更改它。请帮我。谢谢。

   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);

或为 searchViewCloseIcon 设置样式:

<item name="android:searchViewCloseIcon">@drawable/ic_close</item>
<item name="searchViewCloseIcon">@drawable/ic_close</item> (Support Library)

关于Android SearchView X 标记图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19316566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com