Android Selector 按下修改背景和文本顏色的實(shí)現(xiàn)代碼
1,selector 按下修改背景和文本顏色
【1】點(diǎn)擊改變字體顏色 - android:state_pressed(按壓狀態(tài))
【2】selector狀態(tài)選擇器(bg_btn_two (存放 res - drawable)) 資源文件下,否則不起作用
【3】 selector狀態(tài)選擇器(bg_btn_one (存放 res - color)) 資源文件下,否則不起作用
【3】android:state_pressed="true" 必須放在第一行,否則不生效
2,實(shí)現(xiàn)Demo
【1】實(shí)現(xiàn)效果:
【2】實(shí)現(xiàn)代碼
創(chuàng)建selector 文件
在color文件下的selector 文件內(nèi)容
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/colorAccent" android:state_pressed="true"/> //按下時(shí)顯示 <item android:drawable="@color/colorPrimary" /> //默認(rèn)顯示 </selector>
在drawable文件下的selector 文件內(nèi)容
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/colorAccent" android:state_pressed="true"/> <item android:drawable="@color/colorPrimary" /> </selector>
XML文件進(jìn)行調(diào)用: android:background="@drawable/bg_btn_two" 修改背景
android:textColor="@color/bg_btn_one" 修改文字 <Button android:background="@drawable/bg_btn_two" android:textColor="@color/bg_btn_one" android:layout_width="match_parent" android:layout_height="45dp" android:text="點(diǎn)擊改變背景顏色" android:textSize="20sp" android:gravity="center" />
總結(jié)
以上所述是小編給大家介紹的Android Selector 按下修改背景和文本顏色的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)我們網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
上一篇:使用Flutter實(shí)現(xiàn)一個(gè)走馬燈布局的示例代碼
欄 目:Android
下一篇:RecyclerView實(shí)現(xiàn)流式標(biāo)簽單選多選功能
本文標(biāo)題:Android Selector 按下修改背景和文本顏色的實(shí)現(xiàn)代碼
本文地址:http://mengdiqiu.com.cn/a1/Android/9054.html
您可能感興趣的文章
- 01-10Android自定義View之繪制圓形頭像功能
- 01-10Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方法詳解
- 01-10android實(shí)現(xiàn)記住用戶名和密碼以及自動(dòng)登錄
- 01-10android實(shí)現(xiàn)簡單計(jì)算器功能
- 01-10Android 友盟第三方登錄與分享的實(shí)現(xiàn)代碼
- 01-10android實(shí)現(xiàn)指紋識(shí)別功能
- 01-10Emoji表情在Android JNI中的兼容性問題詳解
- 01-10Android實(shí)現(xiàn)圓形漸變加載進(jìn)度條
- 01-10android開發(fā)環(huán)境中SDK文件夾下的所需內(nèi)容詳解
- 01-10android異步消息機(jī)制 源碼層面徹底解析(1)


閱讀排行
本欄相關(guān)
- 01-10Android自定義View之繪制圓形頭像功能
- 01-10Android實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用實(shí)現(xiàn)方
- 01-10android實(shí)現(xiàn)簡單計(jì)算器功能
- 01-10android實(shí)現(xiàn)記住用戶名和密碼以及自動(dòng)
- 01-10C++自定義API函數(shù)實(shí)現(xiàn)大數(shù)相乘算法
- 01-10Android 友盟第三方登錄與分享的實(shí)現(xiàn)代
- 01-10android實(shí)現(xiàn)指紋識(shí)別功能
- 01-10如何給Flutter界面切換實(shí)現(xiàn)點(diǎn)特效
- 01-10Android實(shí)現(xiàn)圓形漸變加載進(jìn)度條
- 01-10Emoji表情在Android JNI中的兼容性問題詳
隨機(jī)閱讀
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 04-02jquery與jsp,用jquery
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10delphi制作wav文件的方法
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 08-05織夢dedecms什么時(shí)候用欄目交叉功能?
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置