最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android復(fù)選框CheckBox與開(kāi)關(guān)按鈕Switch及單選按鈕RadioButton使用示例詳解

 更新時(shí)間:2022年09月27日 14:49:05   作者:Shewyoo  
這篇文章主要介紹了Android復(fù)選框CheckBox與開(kāi)關(guān)按鈕Switch及單選按鈕RadioButton使用示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧

前言 

CompoundButton在XML文件中主要使用下面兩個(gè)屬性。

  • checked:指定按鈕的勾選狀態(tài),true表示勾選,false則表示未勾選,默認(rèn)為未勾選。
  • button:指定左側(cè)勾選圖標(biāo)的圖形資源,如果不指定就使用系統(tǒng)的默認(rèn)圖標(biāo)。

CompoundButton在java代碼中主要使用下列4種方法。

  • setChecked:設(shè)置按鈕的勾選狀態(tài)。
  • setButtonDrawable:設(shè)置左側(cè)勾選圖標(biāo)的圖形資源。
  • setOnCheckedChangeListener:設(shè)置勾選狀態(tài)變化的監(jiān)聽(tīng)器。
  • isChecked:判斷按鈕是否勾選。

一、復(fù)選框CheckBox

    <CheckBox
        android:id="@+id/ck_system"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="系統(tǒng)CheckBox"/>

二、開(kāi)關(guān)按鈕Switch

Switch是開(kāi)關(guān)按鈕,它在選中與取消選中時(shí)可展現(xiàn)的界面元素比復(fù)選框豐富。

Switch控件新添加的XML屬性說(shuō)明如下:

  • textOn:設(shè)置右側(cè)開(kāi)啟時(shí)的文本。
  • textOff:設(shè)置左側(cè)關(guān)閉時(shí)的文本。
  • track:設(shè)置開(kāi)關(guān)軌道的背景。
  • thumb:設(shè)置開(kāi)關(guān)標(biāo)識(shí)的圖標(biāo)。
        <Switch
            android:id="@+id/sw_status"
            android:layout_width="80dp"
            android:layout_height="30dp"
            android:padding="5dp"/>

三、單選按鈕RadioButton

單選按鈕要在一組按鈕種選擇其中一項(xiàng),并且不能多選,這要求有個(gè)容器確定這組按鈕的范圍,這個(gè)容器便是單選組RadioGroup。

RadioGroup實(shí)際上是個(gè)布局,同一組RadioButton都要放在同一個(gè)RadioGroup節(jié)點(diǎn)下,除了RadioButton,也允許放置其他控件。

單選組的用法

判斷選中了哪個(gè)單選按鈕,通常不是監(jiān)聽(tīng)某個(gè)單選按鈕,而是監(jiān)聽(tīng)單選組的選中事件。

RadioGroup常用的3個(gè)方法:

  • check:選中指定資源編號(hào)的單選按鈕。
  • getCheckedRadioButtonId:獲取選中狀態(tài)單選按鈕的資源編號(hào)。
  • setOnCheckedChangeListener:設(shè)置單選按鈕勾選變化的監(jiān)聽(tīng)器。
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="請(qǐng)選擇性別"/>
    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="男"/>
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="女"/>
    </RadioGroup>

到此這篇關(guān)于Android復(fù)選框CheckBox與開(kāi)關(guān)按鈕Switch及單選按鈕RadioButton使用示例詳解的文章就介紹到這了,更多相關(guān)Android按鈕內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

泾川县| 离岛区| 彭山县| 高雄县| 蒲江县| 桐城市| 上犹县| 温宿县| 东山县| 松原市| 和政县| 穆棱市| 武强县| 马龙县| 永年县| 新营市| 正镶白旗| 汶川县| 镇巴县| 商河县| 淄博市| 楚雄市| 兴和县| 富平县| 远安县| 博爱县| 上杭县| 南岸区| 洪湖市| 类乌齐县| 伊金霍洛旗| 纳雍县| 遂平县| 商洛市| 定安县| 綦江县| 自治县| 五指山市| 定安县| 阿克| 南澳县|