在layout文件夾的布局文件activity_main.xml中設(shè)計(jì)如下登陸界面
(1)需將三個(gè)drawable文件,需復(fù)制到drawable文件夾。 editext_selector.xml:編輯框的有無(wú)焦點(diǎn)時(shí)的邊框繪制,引用了下面兩個(gè)文件。 shape_edit_focus.xml:編輯框獲取焦點(diǎn)時(shí)的邊框 shape_edit_normal.xml:編輯框沒(méi)有獲取焦點(diǎn)時(shí)的獲邊框 (2)顏色值文件colors.xml,復(fù)制到values文件夾。
(注:這些文件一般自己都有,附件是完整實(shí)驗(yàn)文件夾,可直接打開(kāi)使用)
MainActivity.java文件: package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView tv_password;
private EditText et_password;
private Button btn_forget;
private RadioGroup rg_login;
private CheckBox ck_remember;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//加載布局
setContentView(R.layout.activity_main);
//獲取控件
tv_password = findViewById(R.id.textView4);
et_password = findViewById(R.id.editText3);
btn_forget = findViewById(R.id.button5);
ck_remember = findViewById(R.id.checkBox);
rg_login = findViewById(R.id.radiogroup);
//單選按鈕組綁定監(jiān)聽(tīng)器
rg_login.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.radioButton3) {
tv_password.setText("登錄密碼:");
et_password.setHint("請(qǐng)輸入密碼");
btn_forget.setText("忘記密碼");
ck_remember.setVisibility(View.VISIBLE);
} else if (checkedId == R.id.radioButton4) {
tv_password.setText("驗(yàn)證碼:");
et_password.setHint("請(qǐng)輸入驗(yàn)證碼");
btn_forget.setText("獲取驗(yàn)證碼");
ck_remember.setVisibility(View.INVISIBLE);
}
}
});
}
}
activity_main.xml文件: <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="197dp"
android:layout_height="wrap_content"
android:text="密碼登錄"
android:textSize="20sp"
android:textStyle="bold" />
<RadioButton
android:id="@+id/radioButton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="驗(yàn)證碼登錄"
android:textSize="20sp"
android:textStyle="bold" />
</RadioGroup>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="120dp"
android:layout_height="35dp"
android:text="手機(jī)號(hào)碼:"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/editText"
android:layout_width="294dp"
android:layout_height="50dp"
android:background="@drawable/editext_selector"
android:ems="10"
android:hint="請(qǐng)輸入手機(jī)號(hào)碼"
android:inputType="phone" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="53dp">
<TextView
android:id="@+id/textView4"
android:layout_width="120dp"
android:layout_height="35dp"
android:text="登錄密碼:"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/editText3"
android:layout_width="200dp"
android:layout_height="match_parent"
android:background="@drawable/editext_selector"
android:ems="10"
android:hint="請(qǐng)輸入密碼"
android:inputType="textPassword" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="忘記密碼" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="42dp">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="120dp"
android:layout_height="42dp"
android:text="記住密碼"
android:textSize="15sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登錄"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
</LinearLayout>
|