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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Android selector 使用注意.

發布時間:2023/11/27 生活经验 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android selector 使用注意. 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下面是幾個是實現的效果

效果圖demo 地址

selector 的作用:

selector 是選擇,用來修改修改控件的背景,設置點擊效果,等, 自己一般使用在點擊之后改變控件的背景色以及文字的顏色,比如底部導航欄切換等, 對單個控件按下一個狀態,松開之后有一個狀態,就是要實現按壓效果,別的沒怎么用得到,

selector 的屬性如下

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

android:state_focused=["true" | "false"]? --是否獲得焦點

android:state_selected=["true" | "false"]? --是否被狀態

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

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

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

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

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

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

android:state_selected=["true" | "false"]? --是否被狀態? 這個是針對list 的item 是否被選中的,

android:state_checked=["true" | "false"]? --是否選中 設計多選的可以使用,比如 CheckBox和RadioButton 等,上面提到導航欄狀態切換就是這個屬性,

下面是一個 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>

?

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。