在Android中,默认情况下,TextView是不带边框的,如果想为TextView添加边框,只能通过“曲线救国”方式来实现-我们可以考虑为TextView设置一个背景,这个背景只是一个边框,这样就实现了带边框的TextView。
配置文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 通过android:background指定背景 -->
<TextView
android:layout_marginTop="25dp"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:text="带边框的文本"
android:background="@drawable/bg_border"
/>
</LinearLayout>
bg_border.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#8DEEEE"/>
</shape>
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dip" android:color="#8DEEEE" />
</shape>
效果如图: