【问题标题】:Why isn't this theme applying to my app?为什么这个主题不适用于我的应用程序?
【发布时间】:2017-12-10 18:24:24
【问题描述】:

我是 Android 开发新手。我希望我的应用具有 Material Design 外观/感觉,因此我尝试将其添加到我的 Android 清单文件中:

<application
  android:label="Repository"
  android:theme="@android:style/Theme.Material"
>
</application>

但是,应用此功能后,应用程序在调试时看起来是一样的。我没有在任何布局文件中明确指定活动栏/背景/等的颜色,所以我不知道为什么会发生这种情况。还有什么我应该做的吗?

编辑:我正在使用 API 级别 24 的 Android 设备进行测试。

【问题讨论】:

  • 什么是“相同”?你怎么知道它没有工作?也许发布您所看到的屏幕截图和您期望的示例。

标签: java android material-design android-manifest


【解决方案1】:

第一:

@android:style/Theme.Material 

需要 API 级别 21+

最好使用您的 styles.xml 并将主题扩展到您的 AppTheme(如果您想自定义)

示例:

<style name="AppTheme" parent="@android:style/Theme.Material">
    <item name="colorAccent">#ffc423</item>
    <item name="colorPrimary">#081d5c</item>
    [...]
</style>

manifest.xml

<application
          [...]
    android:theme="@style/AppTheme">

希望我的回答能帮到你

【讨论】:

  • 我刚刚检查过,我使用的是 API 级别 24。
【解决方案2】:

要使材料主题在较低版本的 android 上也有效,您可以在清单中应用此主题。在colors.xml中定义你的颜色

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

【讨论】:

    猜你喜欢
    • 2019-05-21
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 2018-01-15
    相关资源
    最近更新 更多