如何更改SearchView的关闭图标的分辨率。使用holo.light作为父对象。我试过很多东西!这个名字不在全息图上!!

<item name="android:searchViewCloseIcon">@drawable/ic_search_close</item>

最佳答案

如果您使用的是AppCompat V21compile 'com.android.support:appcompat-v7:22.2.0',则可以使用:

values/themes.xml:
<style name=”Theme.MyTheme” parent=”Theme.AppCompat”>
    <item name=”searchViewStyle”>@style/MySearchViewStyle</item>
</style>
<style name=”MySearchViewStyle” parent=”Widget.AppCompat.SearchView”>
    <!-- Background for the search query section (e.g. EditText) -->
    <item name="queryBackground">...</item>
    <!-- Background for the actions section (e.g. voice, submit) -->
    <item name="submitBackground">...</item>
    <!-- Close button icon -->
    <item name="closeIcon">...</item>
    <!-- Search button icon -->
    <item name="searchIcon">...</item>
    <!-- Go/commit button icon -->
    <item name="goIcon">...</item>
    <!-- Voice search button icon -->
    <item name="voiceIcon">...</item>
    <!-- Commit icon shown in the query suggestion row -->
    <item name="commitIcon">...</item>
    <!-- Layout for query suggestion rows -->
    <item name="suggestionRowLayout">...</item>
</style>

在此处找到:http://android-developers.blogspot.nl/2014/10/appcompat-v21-material-design-for-pre.html
如果你想保持一致,我建议你使用这个库。
如果您真的不想使用这个库,可以使用它来更改关闭图标:
int closeButtonId = getResources().getIdentifier("android:id/search_close_btn", null, null);
ImageView closeButtonImage = (ImageView) searchView.findViewById(closeButtonId);
closeButtonImage.setImageResource(R.drawable.ic_action_cancel);

从这里得到:http://nlopez.io/how-to-style-the-actionbar-searchview-programmatically/

09-10 22:05