android - strokeColor 和 strokeWidth 在 androidx.cardview.widget.CardView android 中不起作用

标签 android material-design android-cardview androidx material-components-android

试图在 cardView 周围做一些边框(androidx.cardview.widget.CardView)

这是代码:

<androidx.cardview.widget.CardView

    android:id="@+id/cardView"
    android:layout_width="273dp"
    android:layout_height="118dp"
    android:layout_marginStart="9dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="9dp"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?android:attr/selectableItemBackground"
    android:orientation="vertical"
    app:cardCornerRadius="8dp"

    android:background="@drawable/fix_border" 
    app:strokeColor="#dedede"
    app:strokeWidth="3dp">

</androidx.cardview.widget.CardView>

结果:

border not showing

还尝试使用自定义形状作为背景( fix_border.xml ),也不起作用。
fix_border.xml :
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="2dp"
        android:color="#dedede" />
    <!--    <solid android:color="#ffffff" />-->
    <padding
        android:bottom="7dp"
        android:left="7dp"
        android:right="7dp"
        android:top="7dp" />
</shape>

最佳答案

只需使用 Material Components LibraryMaterialCardView它扩展了 androidx.cardview.widget.CardView .
就像是:

    <com.google.android.material.card.MaterialCardView
        app:strokeColor="@color/primaryDarkColor"
        app:strokeWidth="3dp"
        ../>

enter image description here

关于android - strokeColor 和 strokeWidth 在 androidx.cardview.widget.CardView android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59976836/

相关文章:

android - 右侧的 float 操作菜单

Android 应用程序无法针对小型设备正确缩放

android - 改变卡片的背景 (Android cardView)

android - AsyncTask内存崩溃

android - 安装react-native-image-crop-picker后构建失败

android - 抽屉 android,删除箭头

css - Material Design Lite 按钮尺寸

android - 为什么 RecyclerView 中的交错网格布局元素在加载图像时会自动交换其位置?

java - 我如何制作不同的按钮,不同的 ImageView 会受到影响

android - AlertDialog 不显示三星 Galaxy s4 中的正负按钮