当前位置:操作系统 > 安卓/Android >>

android中的ImageButton,RadioGroup,CheckBox,ToggleButton

activity_main.xml的配置:

[html] 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
 
    <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/hello_world" 
        tools:context=".MainActivity" /> 
    <!-- 图片按钮 --> 
    <ImageButton  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/home" 
        android:contentDescription="@string/imagetext" 
        /> 
    <!-- 按钮中加图片和文字 --> 
    <Button  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/textbtn" 
        android:drawableRight="@drawable/home"  <!-- 这里的home是在res目录下文件夹drawable中的一张图片,具体哪个drawable应该都可以的 --> 
        /> 
    <!-- Radio组,单选按钮 --> 
    <RadioGroup  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        > 
      <RadioButton  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/nan" 
        /> 
      <RadioButton  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/nv" 
        /> 
    </RadioGroup> 
    <!-- 开关状态按钮 --> 
    <ToggleButton  
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textOff="打开" 
        android:textOn="关闭" 
        /> 
    <!-- checkbox 多选按钮 --> 
    <CheckBox  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="1.江西" 
        /> 
     
     <CheckBox  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="2.福建" 
        /> 
      
      <CheckBox  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="1.浙江" 
        /> 
</LinearLayout> 
strings.xml中主要配置写文本的信息:

[html] 
<resources> 
    <string name="app_name">ImageButton</string> 
    <string name="hello_world">图片按钮</string> 
    <string name="menu_settings">Settings</string> 
    <string name="title_activity_main">MainActivity</string> 
    <string name="imagetext">这是图片按钮</string> 
    <string name="textbtn">按钮文字</string> 
    <string name="nan">男</string> 
    <string name="nv">女</string> 
</resources> 
  

 

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,