6

在此处输入图像描述

我想更改搜索视图组件中显示的白色可绘制 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){}
4

1 回答 1

1
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)
于 2014-01-13T14:29:17.223 回答