MaterialCardView周围没有出现边框

问题描述

我正在尝试在MaterialCardView控件周围添加边框,但是由于某些原因,此方法无法正常工作。我已经添加了相关的依赖项,但是它似乎仍然没有任何作用。

添加依赖项

dependencies {
    ...
    implementation 'com.google.android.material:material:1.0.0'
    ...
}

XML

<?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="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:layout_marginTop="10dp"
    app:cardUseCompatPadding="true"
    app:cardBackgroundColor="@android:color/transparent"
    app:cardElevation="0dp"
    app:strokeColor="@android:color/black"
    app:strokeWidth="2dp">
[...]

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

当前结果

enter image description here

解决方法

 <com.google.android.material.card.MaterialCardView
    android:id="@+id/item_img_card"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_marginBottom="20dp"
     android:layout_marginTop="10dp"
    android:theme="@style/Theme.MaterialComponents.Light"
    app:cardCornerRadius="10dp"
  
    >