轉(zhuǎn)載:blog.csdn.net/swust_chenpeng/article/details/11597165
第一種方法:在drawable文件夾下新建一個(gè)文件設(shè)置背景樣式
代碼:
在drawable文件夾下面新建text_view_border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#80858175" />
<stroke android:width="1dip" android:color="#aea594" />
<corners android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"/>
</shape>
在布局文件調(diào)用
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/text_view_border" />
tv.setBackgroundResource(R.drawable.text_view_border);
分析:
solid設(shè)置填充顏色,顏色值以#80開頭表示透明
stroke 設(shè)置邊框?qū)挾?,顏色?/p>
corners設(shè)置圓角
第二種方法:用圖片設(shè)置background