我想根据android:theme值更改材质工具栏中的溢出菜单图标颜色。
在此示例中,我的搜索图标通过与属性实现相关的一些魔法而受到工具栏主题的影响app:actionViewClass,但我的信息图标则不然。
我的工具栏:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.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:fitsSystemWindows="true"
app:liftOnScroll="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
app:title="@string/app_name"
app:menu="@menu/menu_main"
app:layout_scrollFlags="scroll|enterAlways|snap"/>
</com.google.android.material.appbar.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
我的菜单:
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search_24dp"
app:showAsAction="always"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="TODO" />
<item android:id="@+id/action_info"
android:icon="@drawable/ic_info_24dp"
app:showAsAction="always"
android:title="TODO" />
</menu>
Run Code Online (Sandbox Code Playgroud)
是否存在简单的解决方案?
android android-toolbar material-components material-components-android