gpt4 book ai didi

android - MaterialCardview 需要 Theme.AppCompat

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:03:13 25 4
gpt4 key购买 nike

我正在尝试测试我在新的 Google Material 组件上的技能。但是现在我遇到了 MaterialCardView

的问题

构建过程告诉我

The style on this component requires your app theme to be Theme.AppCompat 
[..]
at com.google.android.material.card.MaterialCardView.<init>

有了这个线索,我添加了style="@style/Theme.AppCompat" & android:theme="@style/Theme.AppCompat"MaterialCardView 也到我在 list 中的 Activity 。

我也尝试将我的 Acitivity 更改为 AppCompatActivity,但没有成功。

我也尝试设置 material.io 文档中告诉的样式但没有成功!

你有一些线索吗?

谢谢

最佳答案

根据 Material Components 1.2.1,您需要这样做:

  • 依赖库实现'com.google.android.material:material:1.2.1'
  • 你需要有 compileSdkVersion 30
  • 您的 Activity 需要扩展 AppCompatActivity(或 use AppCompatDelegate)
  • 你必须使用 Material Components 主题

来源:https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md

开始的最简单方法是为您当前的主题扩展 Theme.MaterialComponents.*.Bridge 而不是 Theme.AppCompat.*

此外,您需要在主题中覆盖以下属性,否则卡片颜色将为 broken :

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
<item name="elevationOverlayEnabled">false</item>
</style>

不要在卡片上设置 android:theme="@style/Theme.MaterialComponents"。您将丢失卡片内每个小部件上主题的颜色信息(主要、次要、重音...)。

不要在卡片上设置style="@style/Theme.MaterialComponentsDon't mix themes and styles.

关于android - MaterialCardview 需要 Theme.AppCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50898379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com