網站首頁 編程語言 正文
前言?
CompoundButton在XML文件中主要使用下面兩個屬性。
- checked:指定按鈕的勾選狀態,true表示勾選,false則表示未勾選,默認為未勾選。
- button:指定左側勾選圖標的圖形資源,如果不指定就使用系統的默認圖標。
CompoundButton在java代碼中主要使用下列4種方法。
- setChecked:設置按鈕的勾選狀態。
- setButtonDrawable:設置左側勾選圖標的圖形資源。
- setOnCheckedChangeListener:設置勾選狀態變化的監聽器。
- isChecked:判斷按鈕是否勾選。
一、復選框CheckBox
<CheckBox android:id="@+id/ck_system" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:text="系統CheckBox"/>
二、開關按鈕Switch
Switch是開關按鈕,它在選中與取消選中時可展現的界面元素比復選框豐富。
Switch控件新添加的XML屬性說明如下:
- textOn:設置右側開啟時的文本。
- textOff:設置左側關閉時的文本。
- track:設置開關軌道的背景。
- thumb:設置開關標識的圖標。
<Switch android:id="@+id/sw_status" android:layout_width="80dp" android:layout_height="30dp" android:padding="5dp"/>
三、單選按鈕RadioButton
單選按鈕要在一組按鈕種選擇其中一項,并且不能多選,這要求有個容器確定這組按鈕的范圍,這個容器便是單選組RadioGroup。
RadioGroup實際上是個布局,同一組RadioButton都要放在同一個RadioGroup節點下,除了RadioButton,也允許放置其他控件。
單選組的用法
判斷選中了哪個單選按鈕,通常不是監聽某個單選按鈕,而是監聽單選組的選中事件。
RadioGroup常用的3個方法:
- check:選中指定資源編號的單選按鈕。
- getCheckedRadioButtonId:獲取選中狀態單選按鈕的資源編號。
- setOnCheckedChangeListener:設置單選按鈕勾選變化的監聽器。
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="請選擇性別"/> <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>
原文鏈接:https://blog.csdn.net/Tir_zhang/article/details/126973628
相關推薦
- 2023-07-18 Spring 中的 Service 有多個實現類如何注入
- 2022-04-30 DataGridView清除顯示的數據、設定右鍵菜單_C#教程
- 2022-07-01 python神經網絡Densenet模型復現詳解_python
- 2022-05-21 Python?requests用法和django后臺處理詳解_python
- 2022-10-17 C++STL教程之vector模板的使用_C 語言
- 2022-08-10 C#實現同步模式下的端口映射程序_C#教程
- 2022-07-12 手把手教你用Redis?實現點贊功能并且與數據庫同步_Redis
- 2022-06-17 Ruby3多線程并行Ractor使用方法詳解_ruby專題
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支