第一種方法:在drawable文件夾下新建一個文件設置背景樣式
代碼:
在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>
在布局文件調用
<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設置填充顏色,顏色值以#80開頭表示透明
stroke 設置邊框寬度,顏色值
corners設置圓角
第二種方法:用圖片設置background
