找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 3145|回復(fù): 0
收起左側(cè)

Android布局管理器及簡(jiǎn)單控件的使用

[復(fù)制鏈接]
ID:856808 發(fā)表于 2020-12-18 23:08 | 顯示全部樓層 |閱讀模式
layout文件夾的布局文件activity_main.xml中設(shè)計(jì)如下登陸界面
圖片6.png             圖片7.png
(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>
布局管理器及簡(jiǎn)單控件的使用.rar (8.6 MB, 下載次數(shù): 13)






評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表