android - 如果 actionBar/Toolbar 是白色的,菜单项上没有波纹

标签 android android-layout toolbar android-toolbar menuitem

我有一个白色的工具栏,其中的菜单项显示为 Action ,是来自 Material 图标的黑色矢量 Assets 。菜单项点击没有波纹效果,因为波纹效果也是白色的。如果工具栏背景更改为其他颜色,例如蓝色,则会出现波纹。如何更改菜单项波纹颜色以使其在白色背景上可见?我试图在 AppTheme 中更改 colorControlHighlight,但它没有更改菜单项波纹颜色。

enter image description here

风格

<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"/>

结果:

enter image description here

编辑

对于操作项:

<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>

结果:

enter image description here

关于android - 如果 actionBar/Toolbar 是白色的,菜单项上没有波纹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43031773/

相关文章:

android - 我们真的还应该支持小屏幕吗?

android - 禁用 CollapsingToolbarLayout 高程

delphi - Delphi 工具按钮(TToolbutton)的剥离效果

android - 具有不同菜单和常用工具栏的 Viewpager 不起作用

android - Android VideoView播放4秒后如何暂停

java - Android 可分块对象在 Activity 之间克隆

android - 相对布局放置到其他相对布局

android 同步适配器安全异常

android - ActionBar 在 Android KitKat 上不可见

Android 工具栏操作按钮不显示