色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

Android控件RadioButton的使用方法

瀏覽:2日期:2022-09-18 18:08:34

本文實例為大家分享了Android控件RadioButton的使用代碼,供大家參考,具體內容如下

內容

Android控件RadioButton的使用方法

<?xml version='1.0' encoding='utf-8'?><RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.RadioActivity'> <RadioGroup //定義一個單選按鈕組android: android:layout_width='wrap_content'android:layout_height='wrap_content'android:orientation='vertical'><RadioButton //單選按鈕一 使用默認樣式 android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:checked='true' android:text='男' android:textSize='24sp' android:textColor='@color/black'/><RadioButton //單選按鈕2 使用默認樣式 android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='女' android:textSize='24sp' android:textColor='@color/black'/> </RadioGroup> <RadioGroup //組2android: android:layout_width='wrap_content'android:layout_height='wrap_content'android:orientation='horizontal'android:layout_below='@id/rg_1'android:layout_marginTop='50dp'><RadioButton android:layout_width='50dp' android:layout_height='wrap_content' android:text='男' android:button='@null' //無按鈕樣式 android:textSize='24sp' android:background='@drawable/selector_radiobutton' //自定義背景 android:textColor='@color/black' android:checked='true' android:gravity='center'/><RadioButton android:layout_width='50dp' android:layout_height='wrap_content' android:gravity='center' android:button='@null' //無按鈕樣式 android:text='女' android:background='@drawable/selector_radiobutton' //自定義背景 android:textSize='24sp' android:textColor='@color/black'/> </RadioGroup></RelativeLayout>

//selector_radiobutton.xml

<?xml version='1.0' encoding='utf-8'?><selector xmlns:android='http://schemas.android.com/apk/res/android'> <item android:state_checked='true'> //單選被選中的樣式<shape android:shape='rectangle'> <solid android:color='#ff66ff'/> <corners android:radius='5dp'/></shape> </item> <item android:state_checked='false'> //單選沒被選中的樣式<shape android:shape='rectangle'> <stroke android:color='#cc33ff' android: /> <corners android:radius='5dp'/></shape> </item></selector>

public class RadioActivity extends AppCompatActivity { private RadioGroup rg_1; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_radio);rg_1 = findViewById(R.id.rg_1);rg_1.setOnCheckedChangeListener((group, checkedId) -> {//設置組中單選按鈕選中事件 RadioButton radioButton = findViewById(checkedId);//獲取被選中的id Toast.makeText(RadioActivity.this,radioButton.getText(),Toast.LENGTH_SHORT) .show();//吐司一下被選中的文本值}); }}

運行效果

Android控件RadioButton的使用方法

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 青青热久久国产久精品秒播 | 亚洲精品久久一区二区无卡 | 一个人看的免费高清视频日本 | 亚洲二区在线播放 | 在线亚洲精品视频 | 日韩毛片免费视频一级特黄 | 免费精品一区二区三区在线观看 | 亚洲欧美在线观看 | 欧美性色生活片天天看99 | 三级三级三级网站网址 | 中美日韩在线网免费毛片视频 | 精品国产欧美一区二区三区成人 | 一级a毛片免费观看 | 国产91精品高清一区二区三区 | 午夜性爽快免费视频播放 | 亚洲综合射 | 欧美一级久久久久久久大 | 国产精品黄在线观看免费软件 | 多人伦精品一区二区三区视频 | 美女被免费视频的网站 | 影院亚洲| 日韩a无吗一区二区三区 | www.av在线免费观看 | 亚洲自偷自拍另类12p | 男女男精品视频在线播放 | 欧美在线视频不卡 | 国产三级在线观看播放 | 国产成人a一区二区 | 在线免费观看成年人视频 | 美女黄网站视频 | 亚洲精品一区二区三区五区 | 91久久线看在观草草青青 | 一级欧美毛片成人 | 91精品国产综合久久久久久 | 国产欧美一区二区成人影院 | 国产精品无码久久久久 | 日本加勒比视频 | 99视频在线精品免费 | 在线一区二区观看 | 亚洲日本视频 | 免费看欧美一级特黄a大片一 |