欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: Android布局管理器及簡單控件的使用 [打印本頁]

作者: dori    時間: 2020-12-18 23:08
標題: Android布局管理器及簡單控件的使用
layout文件夾的布局文件activity_main.xml中設計如下登陸界面
           
(1)需將三個drawable文件,需復制到drawable文件夾。
   editext_selector.xml:編輯框的有無焦點時的邊框繪制,引用了下面兩個文件。
   shape_edit_focus.xml:編輯框獲取焦點時的邊框
   shape_edit_normal.xml:編輯框沒有獲取焦點時的獲邊框
2)顏色值文件colors.xml,復制到values文件夾。

(注:這些文件一般自己都有,附件是完整實驗文件夾,可直接打開使用)

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);
        //單選按鈕組綁定監聽器
        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("請輸入密碼");
                    btn_forget.setText("忘記密碼");
                    ck_remember.setVisibility(View.VISIBLE);
                } else if (checkedId == R.id.radioButton4) {
                    tv_password.setText("驗證碼:");
                    et_password.setHint("請輸入驗證碼");
                    btn_forget.setText("獲取驗證碼");
                    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="驗證碼登錄"
            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="手機號碼:"
            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="請輸入手機號碼"
            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="請輸入密碼"
            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>
布局管理器及簡單控件的使用.rar (8.6 MB, 下載次數: 13)











歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1