我有一个白色的工具栏,其中的菜单项显示为 Action ,是来自 Material 图标的黑色矢量 Assets 。菜单项点击没有波纹效果,因为波纹效果也是白色的。如果工具栏背景更改为其他颜色,例如蓝色,则会出现波纹。如何更改菜单项波纹颜色以使其在白色背景上可见?我试图在 AppTheme 中更改 colorControlHighlight,但它没有更改菜单项波纹颜色。
风格
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#ffffff</item>
</style>
布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.AppBarLayout>
</LinearLayout>
菜单
<?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/menu_action_read_all"
android:icon="@drawable/ic_done_all_black_24dp"
android:title="@string/menu_notifications_read_all"
app:showAsAction="ifRoom" />
</menu>
Activity
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_notifications, menu);
return true;
}
最佳答案
在你的风格中:
<style name="MyToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Light">
<item name="colorControlHighlight">@color/colorAccent</item>
</style>
将此主题应用到您的工具栏:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:popupTheme="@style/MyToolbarTheme"/>
结果:
编辑
对于操作项:
<style name="MyAppBarLayoutTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorControlHighlight">@color/colorAccent</item>
</style>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyAppBarLayoutTheme">
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.AppBarLayout>
结果:
关于android - 如果 actionBar/Toolbar 是白色的,菜单项上没有波纹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43031773/