xml - 无法将形状设置为 TextView 的背景

xml - unable to set shape as background of a TextView

我想在 android:

中设置一个带有描边的透明圆圈作为 TextView 的背景
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="24dp"
        android:background="@drawable/decibel_circle"
        android:text="30 dB"
        android:fontFamily="sans-serif"
        android:textColor="@android:color/black"
        android:textSize="70dp" />
</RelativeLayout>

这是我要使用的形状,位于分贝-circle.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
    <stroke
        android:width="5dp"
        android:color="#F44336">
    </stroke>
    <solid android:color="@android:color/transparent"/>
    <size
        android:width="36dp"
        android:height="36dp" />
    <corners android:radius="12dp" />
    </shape>
</selector>

问题是形状从未显示,无论是在预览中还是在我 运行 我的应用程序中。 我做错了什么?

在您的 decibel-circle.xml 中删除 selector 只需单独使用 shape

只使用这个

 <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
<stroke
    android:width="5dp"
    android:color="#F44336">
</stroke>
<solid android:color="@android:color/transparent"/>
<size
    android:width="36dp"
    android:height="36dp" />
<corners android:radius="12dp" />
</shape>