android中的ImageButton,RadioGroup,CheckBox,ToggleButton

activity_main.xml的配置:

<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中主要配置寫文本的信息:

<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>

效果截圖:



 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章