我想更改搜索 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)

09-11 20:32