日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Android selector 使用注意.

發(fā)布時(shí)間:2023/11/27 生活经验 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android selector 使用注意. 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

下面是幾個(gè)是實(shí)現(xiàn)的效果

效果圖demo 地址

selector 的作用:

selector 是選擇,用來修改修改控件的背景,設(shè)置點(diǎn)擊效果,等, 自己一般使用在點(diǎn)擊之后改變控件的背景色以及文字的顏色,比如底部導(dǎo)航欄切換等, 對(duì)單個(gè)控件按下一個(gè)狀態(tài),松開之后有一個(gè)狀態(tài),就是要實(shí)現(xiàn)按壓效果,別的沒怎么用得到,

selector 的屬性如下

android:state_pressed=["true" | "false"]? --是否觸摸

android:state_focused=["true" | "false"]? --是否獲得焦點(diǎn)

android:state_selected=["true" | "false"]? --是否被狀態(tài)

android:state_checkable=["true" | "false"]? --是否可選

android:state_checked=["true" | "false"]? --是否選中

android:state_enabled=["true" | "false"]? --是否可用

android:state_window_focused=["true" | "false"]? --是否窗口聚焦

以上屬性,如果對(duì)于單個(gè)控件,比如,一個(gè)Button ,一個(gè)Image ,一個(gè)Text 或者是一個(gè)布局, 使用的屬性為: android:state_pressed 其他seleced 或者 checked 屬性即使設(shè)置了也是沒有效果的,

所以使用的時(shí)候要注意下選擇的屬性是否對(duì),一個(gè)Image ,一個(gè)Text 或者是一個(gè)布局使用 android:state_pressed 點(diǎn)擊之后沒有效果,可以在xml 中對(duì)控制設(shè)置android:clickable="true" 這樣就有效果

android:state_selected=["true" | "false"]? --是否被狀態(tài)? 這個(gè)是針對(duì)list 的item 是否被選中的,

android:state_checked=["true" | "false"]? --是否選中 設(shè)計(jì)多選的可以使用,比如 CheckBox和RadioButton 等,上面提到導(dǎo)航欄狀態(tài)切換就是這個(gè)屬性,

下面是一個(gè) RadioButton 切換的代碼

  <RadioGroupandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:orientation="horizontal"><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:button="@drawable/ra_selector_bg"android:textSize="20sp"android:text="單選"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:button="@drawable/mult_selector_bg"android:textSize="20sp"android:text="雙選" /></RadioGroup>
ra_selector_bg
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/single_select" android:state_checked="true" /><item android:drawable="@drawable/single_unselect" /></selector>

?

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

?

總結(jié)

以上是生活随笔為你收集整理的Android selector 使用注意.的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。