Android代碼片段(持續(xù)更新中)

背景圖片中實(shí)現(xiàn)圖片的平鋪效果

在定義的shape中添加背景圖

選中非選中背景切換

選中非選中文本顏色切換

String.xml中引用公共item

ClickableSpan 移除文字下劃線

背景圖片中實(shí)現(xiàn)圖片的平鋪效果

<?xml version="1.0" encoding="utf-8"?>  
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"   
android:src="@drawable/bg"   
android:tileMode="repeat" /> 

在定義的shape中添加背景圖

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" android:padding="10dp">
            <corners
                 android:bottomRightRadius="5dp"
                 android:bottomLeftRadius="5dp"
                 android:topLeftRadius="5dp"
                 android:topRightRadius="5dp"/>
         </shape>
   </item>
   <item android:drawable="@drawable/image_name_here" />
</layer-list>

選中非選中背景切換

在drawable文件夾中創(chuàng)建xml文件,內(nèi)容如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/privacy_top_unselected" android:state_checked="false" />
    <item android:drawable="@drawable/privacy_top_selected" android:state_checked="true" />
    <item android:drawable="@drawable/privacy_top_selected" />
</selector>

選中非選中文本顏色切換

在res文件夾中創(chuàng)建color文件夾,在其中創(chuàng)建xml文件,內(nèi)容如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="@color/white"></item>
    <item android:state_checked="false" android:color="@color/black"></item>
</selector>

String.xml中引用公共item

在resources之上添加

<!DOCTYPE resources [
    <!ENTITY ctrl_policy "\n">
    <!ENTITY span_policy "">
    ]>
<resources>

然后在別的string處按如下方式引用

<string name="dialog_policy_content1">&span_policy;Hello World!</string>

ClickableSpan 移除文字下劃線

關(guān)鍵點(diǎn),重寫(xiě)updateDrawState方法。

  //設(shè)置部分文字點(diǎn)擊事件
        ClickableSpan clickableSpan2 = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
            }
            // 移除下劃線 Described by lxj on 2020/12/22 15:51
            @Override
            public void updateDrawState(@NonNull TextPaint ds) {
                super.updateDrawState(ds);
                ds.setUnderlineText(false);
            }
        };
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容