我想根据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>
我的菜单:
<?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>
有没有简单的解决方案?
1.1.0
、1.2.0-beta01
、1.3.0-alpha01
,它可以正常工作。请注意你的主题叠加中的parent="ThemeOverlay.MaterialComponents.Toolbar.Primary"
。 - Gabriele Mariotti