【问题标题】:Android latest MaterialCardView - white border how to remove it on api 19? [duplicate]Android最新的MaterialCardView - 白色边框如何在api 19上删除? [复制]
【发布时间】:2019-12-13 17:31:29
【问题描述】:

当我在 api 28 上运行我的代码时,我在卡片视图的内边缘看不到这个白色边框。但在 api 19 我得到以下渲染:

我的愿望是让颜色完全填满卡片视图,它应该剪掉角落,这样我就可以保持所需的圆角效果。这是显示其不起作用的简单演示代码:

    <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="300dp"
    android:layout_height="170dp"
    android:theme="@style/Theme.MaterialComponents.Light"
    app:cardBackgroundColor="@android:color/white"
    app:cardCornerRadius="8dp"
    app:cardElevation="4dp"
    app:rippleColor="@android:color/transparent"
    app:strokeWidth="0dp">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_dark" />

</com.google.android.material.card.MaterialCardView>

注意:看看它在 api 28 上呈现时的样子,这正是我想要的:

更新:我调整了

使用 app:cardPreventCornerOverlap="false" ,但使其不四舍五入。当我在它周围设置边框时,它现在不包含在边框中。

有人可以建议吗:

【问题讨论】:

    标签: android material-design


    【解决方案1】:

    只需在您的 xml 中设置 app:cardPreventCornerOverlap="false"

      <?xml version="1.0" encoding="utf-8"?>
    <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="300dp"
        android:layout_height="170dp"
        android:theme="@style/Theme.MaterialComponents.Light"
        app:cardBackgroundColor="@android:color/white"
        app:cardCornerRadius="8dp"
        app:cardElevation="4dp"
        app:rippleColor="@android:color/transparent"
        app:strokeWidth="0dp"
        app:cardPreventCornerOverlap="false" >
    
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/holo_blue_dark" />
    
    </com.google.android.material.card.MaterialCardView>
    

    【讨论】:

    • 是的,有效...奇怪,我在 api 28 上将其设置为 true 并且仍然可以正常工作。不过谢谢。
    • 但现在它不是圆形的,角是方形的。现在如何使它四舍五入?
    【解决方案2】:

    我最终创建了一个我使用的白色边框..所以如果它低于 api 19,我将 strokeColor 设置为白色。这似乎是我能做的最好的。我确实设置了 app:cardPreventCornerOverlap="true" ...它并不完美,但在棒棒糖上实现提升是使用这个 materialCardView 实现的梦想。

    【讨论】:

      猜你喜欢
      • 2019-10-16
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 2018-06-16
      • 2015-05-27
      相关资源
      最近更新 更多