日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android组件的使用:RadioButton

發(fā)布時(shí)間:2024/1/17 Android 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android组件的使用:RadioButton 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?新建一個(gè)Android項(xiàng)目basiccomponent2

1、新建一個(gè)布局文件radiobutton_layout.xml,代碼如下:

?

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout --> 定義線性布局管理器 3 xmlns:android="http://schemas.android.com/apk/res/android"    -->引用命名空間 4 android:layout_width="match_parent"        -->設(shè)置父容器的寬度為屏幕寬度 5 android:layout_height="match_parent"        -->設(shè)置父容器的高度為屏幕高度 6 android:orientation="vertical" >        -->設(shè)置父容器中組件排列方式為垂直 7 8 <!-- RadioButton組件必須包裹在RadioGroup組件中 --> 9 <RadioGroup -->定義RadioGroup容器組件 10 android:id="@+id/rg_sex" -->設(shè)置容器id 11 android:layout_width="match_parent" -->設(shè)置容器寬度為父容器寬度 12 android:layout_height="wrap_content" -->設(shè)置容器高度為包裹內(nèi)容高度 13 android:orientation="horizontal"> -->設(shè)置容器中組件排列方式為水平
14 <!-- 設(shè)置RadioButton組件 --> 15 <RadioButton -->定義RadioButton組件 16 android:id="@+id/rb_sex_male" -->設(shè)置組件id 17 android:layout_width="wrap_content" -->設(shè)置組件寬度為包裹內(nèi)容寬度 18 android:layout_height="wrap_content" -->設(shè)置組件高度為包裹內(nèi)容高度 19 android:text="@string/rb_sex_male_txt"/> -->設(shè)置組件默認(rèn)文本,從string.xml中讀取id為rb_sex_male_txt的內(nèi)容
20 <!-- 設(shè)置RadioButton組件 --> 21 <RadioButton 22 android:id="@+id/rb_sex_female" -->設(shè)置組件id 23 android:layout_width="wrap_content" -->設(shè)置組件寬度為包裹內(nèi)容寬度 24 android:layout_height="wrap_content" -->設(shè)置組件高度為包裹內(nèi)容高度 25 android:text="@string/rb_sex_female_txt"/> -->設(shè)置組件默認(rèn)文本,從string.xml中讀取id為rb_sex_female_txt的內(nèi)容 27 </RadioGroup> 28 </LinearLayout>

2、在string.xml中定義兩個(gè)文本,代碼如下:

1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3 <string name="app_name">BasicComponent2</string> -->應(yīng)用名稱 4 <string name="action_settings">Settings</string> 5 <!-- 定義文本內(nèi)容 --> 6 <string name="rb_sex_male_txt">男</string> -->設(shè)置文本 7 <string name="rb_sex_female_txt">女</string> -->設(shè)置文本 8 </resources>

3、新建一個(gè)RadioButtonActivity類繼承Activity類,并覆寫相應(yīng)方法:

1 package com.example.basiccomponent2; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 6 public class RadioButtonActivity extends Activity { 7 //覆寫父類方法 8 protected void onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState); //調(diào)用父類oncreate()方法 10 super.setContentView(R.layout.radiobutton_layout); //設(shè)置布局管理器 11 } 12 }

4、把RadioButtonActivity配置到AndroidManifest.xml文件中,并設(shè)置程序入口,代碼如下

1 <activity 2 android:name="com.example.basiccomponent2.RadioButtonActivity"   -->Activity類,格式為:包名+類名 或者為:.類名 3 android:label="@string/app_name" >    -->應(yīng)用名 4 <intent-filter>                -->設(shè)置程序主入口,相當(dāng)于java中的main()方法,xml文件中只能有一個(gè)此標(biāo)簽 5 <action android:name="android.intent.action.MAIN" /> 6 <category android:name="android.intent.category.LAUNCHER" /> 7 </intent-filter> 8</activity>

?

2013-07-19

轉(zhuǎn)載于:https://www.cnblogs.com/zhengweicong/p/3201715.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的Android组件的使用:RadioButton的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。