android studio textView 带框
时间: 2023-10-30 16:05:01 浏览: 40
你可以通过在XML布局文件中设置textView的背景属性来添加边框。例如:
```
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/textview_border"
android:text="Hello World!" />
```
然后在drawable文件夹下创建一个名为textview_border.xml的文件,用来定义TextView的边框样式。例如:
```
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#000000" />
<padding
android:left="5dp"
android:right="5dp"
android:top="5dp"
android:bottom="5dp" />
</shape>
```
这个例子中,我们给TextView添加了一个宽度为1dp的黑色边框,并设置了5dp的padding值。你可以根据需要调整这些值来达到你想要的效果。