无法在操作栏中更改图标颜色

时间:2016-09-02 10:32:01

标签: android android-actionbar

我无法找到如何更改操作栏上图标的颜色(右侧搜索和排序图标)。我希望所有图标都像右边的主页图标一样白。 我可以在drawable / ic_search.xml中更改android:fillColor颜色,但我想使用像android:tint这样的东西。

这是我的xml:

layout.xml

    <android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:contentInsetStartWithNavigation="0dp">

        <ImageView
            android:id="@+id/toolbar_logo"
            android:layout_width="32dp"
            android:layout_height="match_parent"
            android:scaleType="fitCenter"
            android:layout_marginRight="16dp"
            app:srcCompat="@drawable/ic_small_logo" />

        <Spinner
            android:id="@+id/toolbar_categories_spinner"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            />

    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

toolbar_menu.xml

 <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:yourapp="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/tools">

   <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_search"
        android:title="@android:string/search_go"

        yourapp:actionViewClass="android.support.v7.widget.SearchView"
        yourapp:showAsAction="always|collapseActionView" />
    <item
        android:id="@+id/action_sort"
        android:icon="@drawable/ic_sort"
        android:title="@string/action_sort"
        yourapp:showAsAction="always" />
</menu>

style.xml

 <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="colorPrimary">#FF3D3D3D</item>
    <item name="android:textColorPrimary">#FFFFFFFF</item>
    <item name="android:textColorSecondary">#FFA7A7A7</item>
</style>

以下是现在的截图:

enter image description here

3 个答案:

答案 0 :(得分:2)

您无法设置其颜色。只需下载并使用白色图标。

答案 1 :(得分:0)

您必须设置白色图标或实际设置颜色

参考

Change color android.support.v7.widget.SearchView

答案 2 :(得分:0)

这可能会对你有帮助,

private void setColor(ImageView imageView) {
    int color = Color.parseColor("#EE3A8C");
    imageView.setColorFilter(color);
}

image = (ImageView) findViewById(R.id.image);
setColor(image);