一区二区日本_久久久久久久国产精品_无码国模国产在线观看_久久99深爱久久99精品_亚洲一区二区三区四区五区午夜_日本在线观看一区二区

Android自定義RadioButton含代碼

Android自定義RadioButton

與默認的Android RadioButton用戶界面不同,我們還可以實現自定義的單選按鈕。愛掏網 - it200.com自定義RadioButton可以使用戶界面更加吸引人。愛掏網 - it200.com

我們來看一個自定義RadioButton的示例。愛掏網 - it200.com

activity_main.xml

文件:activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context="com.example.test.customradiobutton.MainActivity">



    <TextView
        android:id="@+id/tv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:gravity="center_horizontal"
        android:textSize="25dp"
        android:text="Customized Radio Buttons" />


    <!--   Customized RadioButtons  -->


    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/radioGroup">

        <RadioButton
            android:id="@+id/radioMale"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="  Male"
            android:layout_marginTop="10dp"
            android:checked="false"
            android:button="@drawable/custom_radio_button"
            android:textSize="20dp" />

        <RadioButton
            android:id="@+id/radioFemale"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="   Female"
            android:layout_marginTop="20dp"
            android:checked="false"
            android:button="@drawable/custom_radio_button"
            android:textSize="20dp" />
    </RadioGroup>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Show Selected"
        android:id="@+id/button"
        android:onClick="onclickbuttonMethod"
        android:layout_gravity="center_horizontal" />

</LinearLayout>

custom_radio_button.xml

現在在drawable目錄下的另一個文件(custom_radio_button.xml)中實現一個選擇器,并放置兩個不同的選中和未選中的按鈕圖片。愛掏網 - it200.com

文件:checkbox.xml

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true" android:drawable="@drawable/checkedradiobutton" />
    <item android:state_checked="false" android:drawable="@drawable/unchekedradiobutton" />

</selector>

Activity類

文件:MainActivity.java

package com.example.test.customradiobutton;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    Button button;
    RadioButton genderradioButton;
    RadioGroup radioGroup;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        radioGroup=(RadioGroup)findViewById(R.id.radioGroup);
    }


    public void onclickbuttonMethod(View v){
        int selectedId = radioGroup.getCheckedRadioButtonId();
        genderradioButton = (RadioButton) findViewById(selectedId);
        if(selectedId==-1){
            Toast.makeText(MainActivity.this,"Nothing selected", Toast.LENGTH_SHORT).show();
        }
        else{
            Toast.makeText(MainActivity.this,genderradioButton.getText(), Toast.LENGTH_SHORT).show();
        }

    }
}

輸出

聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
發表評論
更多 網友評論0 條評論)
暫無評論

返回頂部

主站蜘蛛池模板: 欧美性生活视频 | 国产精品国产三级国产aⅴ中文 | 亚洲精品66 | 超碰在线97国产 | 日本字幕在线观看 | 欧美电影免费观看高清 | 国产片一区二区三区 | 免费国产视频在线观看 | 国产精品综合一区二区 | 久久精品国产a三级三级三级 | 国产精品1区2区3区 男女啪啪高潮无遮挡免费动态 | 中文字幕一区二区三区日韩精品 | 黄网站在线播放 | av在线一区二区三区 | 日韩中文在线观看 | 综合久久av | 91精品国产乱码久久蜜臀 | 国产精品久久久久久久久久三级 | 资源首页二三区 | 97视频成人 | 亚洲精品91 | 国产精品欧美一区二区 | 久久久tv | 日韩欧美在线观看 | 国产欧美一区二区三区在线播放 | 欧美一区二区三区在线免费观看 | 成人午夜电影在线观看 | 欧美一区二区三区在线观看视频 | 狠狠插天天干 | 三区四区在线观看 | 五月激情婷婷在线 | 免费亚洲视频 | 观看毛片| 日韩在线大片 | 91私密视频 | 久久99久久久久 | 日韩在线一区二区三区 | 亚洲日本一区二区三区四区 | 综合久久久久 | 欧美成人一区二区 | 天天艹日日干 |