【问题标题】:Android Style/Theme is not working as expectedAndroid 样式/主题未按预期工作
【发布时间】:2020-10-25 03:37:33
【问题描述】:

我正在研究 android 主题和样式。作为其中的一部分,我试图改变操作栏的颜色。但是使用我的代码,操作栏的背景已更改,但其标题未显示。请在下面找到我的 theme.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <item name="actionBarStyle">@style/MyActionBar</item> // My change
    </style>

    <style name="MyActionBar">
        <item name="background">@android:color/holo_green_dark</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="titleTextColor">@android:color/white</item>
    </style>

</resources>

现在我得到以下输出

我的代码有什么问题?谁能帮我解决这个问题?

谢谢

【问题讨论】:

    标签: android android-studio styles


    【解决方案1】:

    您需要在此活动中使用 Theme.AppCompat 主题(或后代)。 添加类似这样的父级parent="Theme.AppCompat.Light.DarkActionBar"

    如果没有帮助,请分享您的完整代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      相关资源
      最近更新 更多