Android給TextView設置透明背景、圓角邊框


第一種方法:在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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM