【问题标题】:What is difference of material cardview and just cardview? and why some attrs do not applied?材料卡片视图和卡片视图有什么区别?为什么有些属性不适用?
【发布时间】:2020-05-23 14:21:42
【问题描述】:

例如,我向MaterialCardView 添加了海拔属性,但它不起作用。并且使用background.xml 进行自定义也不起作用。为什么会发生。什么更好用?他们之间

【问题讨论】:

  • 你能用你试过的代码更新你的问题吗...?

标签: android android-cardview material-components-android


【解决方案1】:

最大的区别是使用 MaterialShapeDrawable 作为背景来实现一些 Material 功能,例如 shapingelevation overlays 用于深色主题。
另外MaterialCardView 支持checkingdragging

关于海拔,请使用app:cardElevation 属性。
关于背景检查你的日志。你应该有一个info message:"Setting a custom background is not supported."

【讨论】:

    【解决方案2】:

    这个link有关于卡片视图和材料卡片视图差异的有用信息。 并回答第二个问题: 使用材质组件需要材质组件主题。 确保在您的项目中使用材质主题以便能够自定义视图。

    <resources>
      <!-- inherit from the material theme -->
      <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Main theme colors -->
        <!--   your app branding color for the app bar -->
        <item name="android:colorPrimary">@color/primary</item>
        <!--   darker variant for the status bar and contextual app bars -->
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <!--   theme UI controls like checkboxes and text fields -->
        <item name="android:colorAccent">@color/accent</item>
      </style>
    </resources>
    

    【讨论】:

      【解决方案3】:

      关于海拔,请改用app:cardElevation 关于背景,请使用app:cardBackgroundColor

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-11-28
        • 1970-01-01
        • 1970-01-01
        • 2016-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多