第一種方法:在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設置圓角
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。