久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: 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://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 综合精品 | 国产一区二区在线91 | 在线激情视频 | 在线视频一区二区 | 欧洲亚洲一区 | 中国一级大毛片 | 欧美久久国产精品 | 成人在线中文字幕 | 99亚洲国产精品 | 国产成人精品一区二区三区视频 | 久久久久久亚洲精品 | 亚洲视频一区在线播放 | 国产视频第一页 | 亚洲aⅴ| 一级毛片免费看 | 精精久久 | 草草影院ccyy | h视频在线观看免费 | 午夜电影在线播放 | 欧美一级在线视频 | 中文字幕久久精品 | 999热视频 | 久久综合久| 午夜一区二区三区 | 久久国产成人午夜av影院武则天 | 日韩精品一区二区久久 | 精品久久久一区 | 欧美涩 | 一级黄色片网址 | 国产精品久久久久久 | 欧美日韩一区二区在线观看 | 国产麻豆一区二区三区 | 国产一区精品 | 91免费福利在线 | 四虎影院在线免费观看 | 欧美一级二级三级 | 色永久| 久久久久国产精品一区 | 久久区二区 | 精品欧美一区二区三区久久久 | 欧美日韩国产欧美 |