国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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
相關文章:
主站蜘蛛池模板: 久久福利青草精品资源站免费 | 特黄毛片 | 三级毛片基地 | 国产猛烈无遮掩视频免费网站男女 | 国产日本在线 | 久久久精品一区二区三区 | 欧美成人网7777视频 | 中文字幕亚洲视频 | 国产日韩一区二区三区在线播放 | 亚洲精品系列 | 成人综合在线视频 | 中文字幕一区在线 | 亚洲欧美性视频 | 香港三级日本三级三级人妇 | 成人观看网站a | 俺来也俺来也天天夜夜视频 | 国产精品一区二区丝瓜 | 普通话对白国产情侣自啪 | 国产成人亚洲日本精品 | 夜色www国产精品资源站 | 欧美成年人网站 | 欧美日韩精品一区二区三区视频播放 | 久久精品成人国产午夜 | 91大神在线精品视频一区 | 337p粉嫩日本亚洲大胆艺术照 | 国产精品一一在线观看 | 最近中文在线中文 | 亚洲国产精品久久综合 | 久久国内精品自在自线软件 | 一级做a爱久久久久久久 | 国产高清在线精品一区在线 | 免费国产成人综合 | 91久久国产视频 | 中文国产成人精品久久水 | 一国产一级淫片a免费播放口 | 久久riav.com| 久久院线 | 国产亚洲高清在线精品不卡 | 日韩精品一区二区三区不卡 | 国产95在线 | 亚洲 | 美女黄视频免费观看 |