【问题标题】:OverFlow Menu on Dark Theme colours are wrong when using Theme.MaterialComponents.DayNight.NoActionBar使用 Theme.MaterialComponents.DayNight.NoActionBar 时,深色主题颜色上的溢出菜单错误
【发布时间】:2020-05-07 06:48:21
【问题描述】:

我正在使用 MaterialDesign website 中描述的指南中的实现

无论我尝试什么,菜单文本颜色和本机菜单图标(如展开菜单图标)都是错误的颜色,特别是它们似乎是浅色模式颜色。我希望它们是深色主题文本(白色文本和深色表面上的本机菜单图标)。

其他方面都很好,例如工具栏、卡片视图、文本和其他表面。

据我了解,这应该无需任何代码修改即可工作,并且当出现在库存溢出菜单的“表面”上时,文本颜色应自动更改为浅色。

我不相信我会在任何地方覆盖它。我所知道的项目中没有其他样式。

示例:

我的样式.xml:

<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorSecondary">@color/colorSecondary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorControlActivated">@color/colorControlActivated</item>
</style>

build.gradle:

android {
   compileSdkVersion 29

   defaultConfig {
       applicationId "poop"
       minSdkVersion 17
       targetSdkVersion 29
       versionCode 24
       versionName "3.2.2"
       multiDexEnabled true
       vectorDrawables.useSupportLibrary = true
   }
   compileOptions {
       sourceCompatibility = 1.8
       targetCompatibility = 1.8
   }
}

我已经尝试了一些与 stackoverflow 上的菜单问题相关的主题覆盖建议。大多数不修复文本,它仍然是黑色的。

有些确实修复了文本,但其他项目(例如用于展开子菜单的 V 形)在深色表面上保持黑色。

【问题讨论】:

  • 你用的是哪个版本?

标签: android android-styles android-dark-theme


【解决方案1】:

您可以覆盖工具栏上的popupTheme(用于弹出菜单),以便它使用colorOnSurface 作为文本颜色。

<style name="ThemeOverlay.MyApp.Toolbar" parent="@style/ThemeOverlay.MaterialComponents.Toolbar">
    <item name="popupTheme">@style/ThemeOverlay.MyApp.PopupTheme</item>
</style>

<style name="ThemeOverlay.MyApp.PopupTheme" parent="">
    <item name="android:textColorPrimary">?attr/colorOnSurface</item>
</style>

如果您使用MaterialToolbar,您可以在应用中以默认样式应用此覆盖(因为MaterialToolbar 支持materialThemeOverlay):

<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    ...
    <item name="colorSurface">@color/white</item>
    <item name="colorOnSurface">@color/black</item>
    <item name="toolbarStyle">@style/Widget.MyApp.Toolbar</item>
</style>

<style name="Widget.MyApp.Toolbar" parent="@style/Widget.MaterialComponents.Toolbar">
     <item name="materialThemeOverlay">@style/ThemeOverlay.MyApp.Toolbar</item>
</style>

如果您使用Toolbar,则必须在Toolbar 声明本身的布局中使用android:theme=“@style/ThemeOverlay.MyApp.Toolbar” 设置它。

values-night/themes.xml 中,您必须将colorSurfacecolorOnSurface 设置为暗模式下所需的颜色。我建议重新调整您的主题,以避免在值相同的情况下重复定义。

【讨论】:

    猜你喜欢
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多