试图在 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>
结果:
还尝试使用自定义形状作为背景(
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 Library和 MaterialCardView
它扩展了 androidx.cardview.widget.CardView
.
就像是:
<com.google.android.material.card.MaterialCardView
app:strokeColor="@color/primaryDarkColor"
app:strokeWidth="3dp"
../>
关于android - strokeColor 和 strokeWidth 在 androidx.cardview.widget.CardView android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59976836/