[英]xml - unable to set shape as background of a TextView
I'm trying to set a transparent circle with a stroke as the background of a TextView in android: 我试图设置一个带有笔触的透明圆圈作为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>
And this is the shape I want to use, located in decibel-circle.xml 这是我要使用的形状,位于decibel-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>
The problem is that the shape is never shown, neither in the preview nor when I run my app. 问题在于,无论是在预览中还是在运行应用程序时,都不会显示形状。 What am I doing wrong? 我究竟做错了什么?
in your decibel-circle.xml
remove selector
just use shape
alone 在您decibel-circle.xml
删除selector
只需单独使用shape
Use this only 仅使用此
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.