【问题标题】:SnackBar using ActionBar Theme?SnackBar 使用 ActionBar 主题?
【发布时间】:2019-06-12 10:42:44
【问题描述】:

我对 ActionBar 和 Snackbar 的样式有这种奇怪的行为。 我有AppTheme的以下主题

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorWhite</item>
    <item name="colorPrimaryDark">@color/colorWhiteDark</item>
    <item name="colorAccent">@color/colorGreen</item>
</style>

所以,我有白色主题。而我的SnackBar 看起来像这样

但是,每当我添加自定义 actionBarTheme,比如

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorWhite</item>
    <item name="colorPrimaryDark">@color/colorWhiteDark</item>
    <item name="colorAccent">@color/colorGreen</item>
    <item name="actionBarTheme">@style/ActionbarTheme</item>

</style>
<style name="ActionbarTheme">
    <item name="android:textColor">@color/colorBlack</item>
    <item name="android:background">@color/colorWhite</item>
</style>

我的 SnackBar 看起来像这样

为什么会导致这种行为以及如何解决?

【问题讨论】:

    标签: android android-actionbar android-theme android-styles android-snackbar


    【解决方案1】:

    由于您在父母中应用以下样式

    <style name="ActionbarTheme">
        <item name="android:textColor">@color/colorBlack</item>
        <item name="android:background">@color/colorWhite</item>
    </style>
    

    您的文本颜色为黑色,背景为白色。

    编辑:

    要修复,您需要将 textcolor 设置为白色和背景黑色:

    <style name="ActionbarTheme">
        <item name="android:textColor">@color/colorWhite</item>
        <item name="android:background">@color/colorBlack</item>
    </style>
    

    【讨论】:

    • 这到底是如何回答这个问题的? OP 想知道为什么将他们的样式应用到 actionBarTheme 会改变他们小吃店的主题以及如何修复它。
    • @CarsonJ。 OP 询问“为什么会导致这种行为”,我已经给出了相同的答案,并且我已经编辑了我的答案以满足他的第二个问题,即“如何解决它”
    【解决方案2】:

    将项目名称背景更改为 colorPrimary

    <style name="ActionbarTheme">
        <item name="android:textColor">@color/colorBlack</item>
        <item name="colorPrimary">@color/colorWhite</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多