Android 給textview添加下劃線的一種方法(可複用)

如下效果圖:

在佈局中給textview添加個背景就ok了

              <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/underline_text"
                android:onClick="seeAgreement"
                android:text="@string/register_agreement"
                android:textSize="12sp"
                android:textStyle="bold" />

然後主要是background的xml文件

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 邊框顏色值 -->
    <item>
        <shape>
            <solid android:color="#ff4A4A4A" /><!--下劃線顏色-->
        </shape>
    </item>
    <item android:bottom="1px"> <!--下劃線厚度-->
        <shape>
            <solid android:color="#ffffff" /><!--背景色 不能透明否則會顯示上面的下劃線顏色-->
        </shape>
    </item>

</layer-list>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章