1. 程式人生 > 實用技巧 >android--註冊介面

android--註冊介面

java介面

 1 packagecom.example.myapplication;
 2 
 3 importandroidx.appcompat.app.AppCompatActivity;
 4 
 5 importandroid.os.Bundle;
 6 importandroid.widget.RadioButton;
 7 importandroid.widget.RadioGroup;
 8 importandroid.widget.Toast;
 9 
10 publicclassRadioActivityextendsAppCompatActivity {
11 private
RadioGroup mRg1; 12 @Override 13 protectedvoidonCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.zhuce); 16 mRg1 = findViewById(R.id.Rad1); 17 mRg1.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener() { 18 @Override 19 publicvoidonCheckedChanged(RadioGroup radioGroup,int
i) { 20 RadioButton radioButton= radioGroup.findViewById(i); 21 Toast.makeText(RadioActivity.this,radioButton.getText(),Toast.LENGTH_SHORT).show(); 22 } 23 }); 24 } 25 }

xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3
android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:padding="10dp"> 6 <TextView 7 android:id="@+id/text1" 8 android:layout_width="600dp" 9 android:layout_height="38dp" 10 android:text="請選擇你的性別為:" 11 android:textSize="32dp" 12 android:textColor="#000000"/> 13 <RadioGroup 14 android:id="@+id/Rad1" 15 android:orientation="horizontal" 16 android:layout_below="@id/text1" 17 android:layout_width="wrap_content" 18 android:layout_height="32dp"> 19 <RadioButton 20 android:layout_width="wrap_content" 21 android:layout_height="wrap_content" 22 android:layout_marginLeft="50dp" 23 android:textSize="20dp" 24 android:text="男"/> 25 <RadioButton 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:layout_marginLeft="80dp" 29 android:textSize="20dp" 30 android:text="女"/> 31 </RadioGroup> 32 <EditText 33 android:layout_marginTop="40dp" 34 android:id="@+id/Edi1" 35 android:layout_below="@id/Rad1" 36 android:layout_width="match_parent" 37 android:layout_height="wrap_content" 38 android:drawableLeft="@drawable/bianjiziliao" 39 android:hint="請輸入使用者名稱:" 40 android:background="@drawable/button_zhuce" 41 android:maxLines="1" /> 42 <EditText 43 android:id="@+id/Edi2" 44 android:layout_below="@id/Edi1" 45 android:layout_width="match_parent" 46 android:layout_height="wrap_content" 47 android:hint="請輸入手機號:" 48 android:drawableLeft="@drawable/shouji" 49 android:background="@drawable/button_zhuce" 50 android:maxLines="1" /> 51 <EditText 52 android:id="@+id/Edi3" 53 android:layout_below="@id/Edi2" 54 android:layout_width="match_parent" 55 android:layout_height="wrap_content" 56 android:hint="請輸入郵箱:" 57 android:drawableLeft="@drawable/youxiang" 58 android:background="@drawable/button_zhuce" 59 android:maxLines="1" /> 60 <EditText 61 android:id="@+id/Edi4" 62 android:layout_below="@id/Edi3" 63 android:layout_width="match_parent" 64 android:layout_height="wrap_content" 65 android:background="@drawable/button_zhuce" 66 android:hint="請輸入密碼:" 67 android:drawableLeft="@drawable/mima" 68 android:maxLines="1" /> 69 <EditText 70 android:id="@+id/Edi5" 71 android:layout_below="@id/Edi4" 72 android:layout_width="match_parent" 73 android:layout_height="wrap_content" 74 android:background="@drawable/button_zhuce" 75 android:hint="再次驗證密碼:" 76 android:drawableLeft="@drawable/mima" 77 android:maxLines="1" /> 78 <TextView 79 android:layout_marginTop="30dp" 80 android:layout_below="@id/Edi5" 81 android:layout_width="match_parent" 82 android:layout_height="wrap_content" 83 android:text="點選[註冊]按鈕即代表同意《老吳克註冊協議》" 84 android:gravity="center" 85 android:textColor="#ff9900"/> 86 <Button 87 android:layout_marginTop="60dp" 88 android:layout_below="@id/Edi5" 89 android:layout_width="match_parent" 90 android:layout_height="50dp" 91 android:textColor="#ffffff" 92 android:background="@drawable/bg_btn4" 93 android:text="註冊" 94 android:textSize="20dp"/> 95 96 97 </RelativeLay>