更改SearchView返回图标颜色

时间:2016-02-25 19:08:28

标签: android android-fragments

有可能在SearchView扩展时更改SearchView上显示的箭头的颜色吗? enter image description here

我已经尝试了一切没有结果。

5 个答案:

答案 0 :(得分:9)

要更改ng-hide="$ctrl.nsCollapsibleHeader.showCollapsed"工具栏

中的后退图标颜色,请添加以下属性
android.support.v7.widget.Toolbar

另外,要更改关闭按钮图标,请添加以下代码

app:collapseIcon="@drawable/back_arrow"

答案 1 :(得分:1)

请参阅Abdul Rahman的回答(Styling a SearchView in Android Action Bar

@Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.main_menu, menu);
        restoreActionBar();

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        MenuItem searchMenuItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

        SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
        searchAutoComplete.setHintTextColor(Color.WHITE);
        searchAutoComplete.setTextColor(Color.WHITE);

        View searchplate = (View)searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
        searchplate.setBackgroundResource(R.drawable.texfield_searchview_holo_light);

        ImageView searchCloseIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
        searchCloseIcon.setImageResource(R.drawable.clear_search);

        ImageView voiceIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_voice_btn);
        voiceIcon.setImageResource(R.drawable.abc_ic_voice_search);

        ImageView searchIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
        searchIcon.setImageResource(R.drawable.abc_ic_search);


        return super.onCreateOptionsMenu(menu);
    }

答案 2 :(得分:0)

这是另一种方法:

<style name="ActivityTheme" parent="@android:style/Theme.DeviceDefault.Light">
    <item name="android:actionBarTheme">@style/searchActionBarTheme</item>
</style>

<style name="searchActionBarTheme" parent="@android:style/ThemeOverlay.Material.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/back_key_color</item> <!-- back key color defined here!! -->
    <item name="android:actionBarWidgetTheme">@style/searchViewTheme</item>
</style>

<style name="searchViewTheme" parent="@android:style/ThemeOverlay.Material.Light">
    <item name="android:editTextColor">@color/edit_text_color</item>
    <item name="android:colorControlActivated">@color/search_cursor_color</item>
</style>

在Manifest.xml中使用ActivityTheme作为您的活动

答案 3 :(得分:0)

我正在工具栏中使用SearchView,并且可以使用Reflection更改颜色。

try {
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    Field mCollapseIcon = toolbar.getClass().getDeclaredField("mCollapseIcon");
    mCollapseIcon.setAccessible(true);
    Drawable drw = (Drawable) mCollapseIcon.get(toolbar);
    drw.setTint(color);
}
catch (Exception e) {
}

答案 4 :(得分:0)

更改SearchView关闭图标颜色

SearchView  searchView = (SearchView) findViewById(R.id.searchView1);

    ImageView searchClose  = (ImageView) searchView.findViewById(search.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null));

    searchClose.setColorFilter (R.color.black);