Android編程之selector下設(shè)置背景屬性值的方法
本文實(shí)例講述了Android編程之selector下設(shè)置背景屬性值的方法。分享給大家供大家參考,具體如下:
在res/drawable文件夾新增一個文件,此文件設(shè)置了圖片的觸發(fā)狀態(tài),你可以設(shè)置 state_pressed,state_checked,state_pressed,state_selected,state_focused,state_enabled 等幾個狀態(tài):
android:state_pressed
Boolean. "true" if this item should be used when the object is pressed (such as when a button is touched/clicked); "false" if this item should be used in the default, non-pressed state.
如果是true,當(dāng)被點(diǎn)擊時(shí)顯示該圖片,如果是false沒被按下時(shí)顯示默認(rèn)。
android:state_focused
Boolean. "true" if this item should be used when the object is focused (such as when a button is highlighted using the trackball/d-pad); "false" if this item should be used in the default, non-focused state.
true,獲得焦點(diǎn)時(shí)顯示;false,沒獲得焦點(diǎn)顯示默認(rèn)。
android:state_selected
Boolean. "true" if this item should be used when the object is selected (such as when a tab is opened); "false" if this item should be used when the object is not selected.
true,當(dāng)被選擇時(shí)顯示該圖片;false,當(dāng)未被選擇時(shí)顯示該圖片。
android:state_checkable
Boolean. "true" if this item should be used when the object is checkable; "false" if this item should be used when the object is not checkable. (Only useful if the object can transition between a checkable and non-checkable widget.)
true,當(dāng)CheckBox能使用時(shí)顯示該圖片;false,當(dāng)CheckBox不能使用時(shí)顯示該圖片。
android:state_checked
Boolean. "true" if this item should be used when the object is checked; "false" if it should be used when the object is un-checked.
true,當(dāng)CheckBox選中時(shí)顯示該圖片;false,當(dāng)CheckBox為選中時(shí)顯示該圖片。
android:state_enabled
Boolean. "true" if this item should be used when the object is enabled (capable of receiving touch/click events); "false" if it should be used when the object is disabled.
true,當(dāng)該組件能使用時(shí)顯示該圖片;false,當(dāng)該組件不能使用時(shí)顯示該圖片。
android:state_window_focused
Boolean. "true" if this item should be used when the application window has focus (the application is in the foreground), "false" if this item should be used when the application window does not have focus (for example, if the notification shade is pulled down or a dialog appears).
true,當(dāng)此activity獲得焦點(diǎn)在最前面時(shí)顯示該圖片;false,當(dāng)沒在最前面時(shí)顯示該圖片。
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/button_pressed"/><!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/button_focused"/><!-- focused --> <itemandroid:drawable="@drawable/button_normal"/><!-- default --> </selector>
更多關(guān)于Android開發(fā)相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》
希望本文所述對大家Android程序設(shè)計(jì)有所幫助。
相關(guān)文章
利用Android 防止系統(tǒng)字體變化、顯示大小變化影響
這篇文章主要介紹了利用Android 防止系統(tǒng)字體變化、顯示大小變化影響方法的相關(guān)資料,需要的朋友可以參考下面文章的具體內(nèi)容,希望對你有所幫助2021-10-10android-wheel控件實(shí)現(xiàn)三級聯(lián)動效果
這篇文章主要為大家詳細(xì)介紹了android-wheel控件實(shí)現(xiàn)三級聯(lián)動效果的代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Android編程獲取并設(shè)置Activity亮度的方法
這篇文章主要介紹了Android編程獲取并設(shè)置Activity亮度的方法,涉及Android針對屏幕亮度的相關(guān)操作技巧,需要的朋友可以參考下2015-12-12Android解析json數(shù)組對象的方法及Apply和數(shù)組的三個技巧
這篇文章主要介紹了Android解析json數(shù)組對象的方法及Apply和數(shù)組的三個技巧的相關(guān)資料,需要的朋友可以參考下2015-12-12Notification消息通知 自定義消息通知內(nèi)容布局
這篇文章主要為大家詳細(xì)介紹了Notification消息通知,消息合并且顯示條數(shù),自定義消息通知內(nèi)容布局,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09Android Presentation實(shí)現(xiàn)雙屏異顯
這篇文章主要為大家詳細(xì)介紹了Android Presentation實(shí)現(xiàn)雙屏異顯,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01