av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

Android控件RadioButton的使用方法

瀏覽:6日期: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
相關文章:
主站蜘蛛池模板: 91欧美日韩 | 国产在线视频网站 | 四虎在线免费观看视频 | 亚洲福利专区 | 综合伊人| 久久99精品久久久久久琪琪 | 精品国产欧美 | 亚洲午夜久久 | 日韩和的一区二区 | 成人黄色在线 | 在线观看的av网站 | 国产三级午夜理伦三级 | 亚洲综合天堂 | 中文字幕欧美在线 | 国产专区在线播放 | 国产免费一区二区三区免费视频 | 亚洲精品三区 | 天堂资源在线 | 青青草久久 | 国产精品久久一区二区三区 | 一级久久 | 国产无精乱码一区二区三区 | 一区二区国产精品 | 国产综合在线视频 | 日韩欧美视频在线 | 亚洲在线一区二区 | 国产成人免费在线视频 | 久久久久久久综合 | 亚洲欧美一区二区三区四区 | 精品久| 欧美又大粗又爽又黄大片视频 | 久久最新 | 欧美成年人视频 | 色综合色综合 | 天堂影院av| 国产又粗又长又爽 | 日韩在线精品视频 | 久久草视频 | 999精品视频 | 国产一区二区精品丝袜 | 欧美日韩免费在线 |