【问题标题】:Custom Material Style not Working自定义材质样式不起作用
【发布时间】:2015-08-17 19:50:40
【问题描述】:

我有一个使用 min sdk 18 的应用程序,在没有材料主题样式的情况下可以正常工作,但是当我将材料样式放入 values-v21 时,应用程序一启动就崩溃了。我已经确认这是导致崩溃的原因。
我已经看到了 Holo 样式的解决方案,您必须使用 Base.AppCompat.Holo.Dark 作为父级。材料有类似的东西吗?
我已经从下面的 values-v21 目录中附加了 styles.xml。请询问您是否需要更多信息。
Android Studio 1.2 on Windows 8.1 在 OnePlus One 上测试

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/accent</item>
</style>
</resources>

【问题讨论】:

标签: android android-layout android-studio material-design android-styles


【解决方案1】:

使用 AppCompat 代替 Material

dependencies {
    compile "com.android.support:appcompat-v7:21.0.+"
}

主题:

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- Set AppCompat’s actionBarStyle -->
    <item name="actionBarStyle">@style/MyActionBarStyle</item>

    <!-- Set AppCompat’s color theming attrs -->
    <item name=”colorPrimary”>@color/my_awesome_red</item>
    <item name=”colorPrimaryDark”>@color/my_awesome_darker_red</item>

    <!-- The rest of your attributes -->
</style>

【讨论】:

  • 谢谢,它现在可以工作了。如果我的最低 SDK 级别为 21,自定义其余元素是否与我的操作相同?
  • 没关系,我在 android 开发者页面上找到了一个部分。 link 。谢谢
猜你喜欢
  • 1970-01-01
  • 2019-06-02
  • 2020-12-17
  • 2015-03-21
  • 2020-04-18
  • 2019-02-02
  • 2021-09-20
  • 1970-01-01
相关资源
最近更新 更多