Android 如何在textview周围设置边框?

Android 如何在textview周围设置边框?,android,textview,border,Android,Textview,Border,border.xml(位于可绘制文件夹中) activity_main.xml <TextView android:id="@+id/textView" android:layout_width="100dp" android:layout_height="20dp" android:layout_marginBottom="16dp" android:layout_marginEnd="16dp" android:layout_marg

border.xml(位于可绘制文件夹中)


activity_main.xml

<TextView
    android:id="@+id/textView"
    android:layout_width="100dp"
    android:layout_height="20dp"
    android:layout_marginBottom="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:background="@drawable/border"
    android:text="TextView"
    android:textSize="20sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>


我无法使用上述代码获取textview中的边框。约束布局宽度和高度设置为与父项匹配

我认为您在border.xml文件中错了

尝试使用以下方法进行测试:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <solid android:color="#ffffff" />
   <stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>


如果它起作用,就意味着语法有问题。(可能选择器使用不当)

我认为您在border.xml文件中错了

尝试使用以下方法进行测试:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <solid android:color="#ffffff" />
   <stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>


如果它起作用,就意味着语法有问题。(可能选择器使用不当)

设置宽度和高度以包装内容。并从文本视图中删除约束从边框中删除选择器和填充。xml@ZakiPathan它不起作用。尝试过。@VivekMishra删除选择器和填充无效。如果没有,我应该在哪里添加填充?使用您的形状标签定义形状,如下所示
android:shape=“rectangle”
设置宽度和高度以包装内容。并从文本视图中删除约束从边框中删除选择器和填充。xml@ZakiPathan它不起作用。尝试过。@VivekMishra删除选择器和填充无效。如果没有,我应该在哪里添加填充?使用您的形状标签定义形状,如下所示
android:shape=“rectangle”
谢谢。我搞错了形状标签中res前面有一个空格!谢谢我搞错了形状标签中res前面有一个空格!