影片直播原始碼,AndroidStudio登入頁面的切換

zhibo系統開發發表於2023-10-11

影片直播原始碼,AndroidStudio登入頁面的切換

xml程式碼

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="
    xmlns:app="
    xmlns:tools="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:padding="10dp"
    >
 
<!--        登入方式的選擇-->
    <RadioGroup
        android:id="@+id/login"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="15dp">
        <RadioButton
            android:id="@+id/password_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="密碼登入"
            android:textSize="18dp"
            />
        <RadioButton
            android:id="@+id/yzm_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="80dp"
            android:text="驗證碼登入"
            android:textSize="18dp"
            />
    </RadioGroup>
    <!--        手機號碼-->
    <LinearLayout
        android:id="@+id/phone"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_marginTop="10dp"
        android:layout_below="@+id/login">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="手機號碼:"
            android:textSize="20dp" />
        <EditText
            android:layout_width="270dp"
            android:layout_height="50dp"
            android:singleLine="true"
            android:hint="請輸入手機號"
            android:background="@drawable/editext_selector"
            />
    </LinearLayout>
<!--        登入密碼-->
    <LinearLayout
        android:id="@+id/password_view"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_marginTop="10dp"
        android:layout_below="@+id/phone">
 
        <TextView
            android:id="@+id/password_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登入密碼:"
            android:textSize="20dp" />
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <EditText
                    android:id="@+id/password_value"
                    android:layout_width="160dp"
                    android:layout_height="50dp"
                    android:singleLine="true"
                    android:hint="請輸入密碼"
                    android:background="@drawable/editext_selector"
                    tools:ignore="MissingConstraints" />
 
                <Button
                    android:id="@+id/login_yzm"
                    android:layout_width="110dp"
                    android:layout_height="50dp"
                    android:layout_toEndOf="@id/password_value"
                    android:text="登入"
                    android:background="@color/colorPrimaryDark"/>
            </RelativeLayout>
 
 
    </LinearLayout>
    <CheckBox
        android:id="@+id/btn_forget"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="記住密碼"
        android:layout_below="@id/password_view"/>
 
    <Button
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/btn_forget"
        android:gravity="center"
        android:text="登入" />
<!--    未解決的bug:
    1.輸入框的寬度螢幕自適應
    2.密碼設定為不可見,驗證碼可見(JAVA更改編輯框的屬性)
-->
</RelativeLayout>


 【Java程式碼】

package com.example.a10133;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.text.InputType;
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 {
    TextView password_txt;
    EditText password_value;
    Button login_yzm;
    RadioGroup login;
    CheckBox btn_forget;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //載入佈局
        setContentView(R.layout.activity_main);
        //獲取控制元件
//        密碼登入
        password_txt = findViewById(R.id.password_txt);
//        輸入的密碼框
        password_value = findViewById(R.id.password_value);
//        登入及獲取驗證碼按鈕
        login_yzm = findViewById(R.id.login_yzm);
//        忘記密碼按鈕
        btn_forget = findViewById(R.id.btn_forget);
//        選擇兩種登入方式
        login = findViewById(R.id.login);
        //單選按鈕組繫結監聽器
        login.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.password_login) {
                    password_txt.setText("登入密碼:");
                    password_value.setHint("請輸入密碼");
                    login_yzm.setText("登入");
                    btn_forget.setVisibility(View.VISIBLE);
                } else if (checkedId == R.id.yzm_login) {
                    password_txt.setText("    驗證碼:");
                    password_value.setHint("請輸入驗證碼");
                    login_yzm.setText("獲取驗證碼");
                    btn_forget.setVisibility(View.INVISIBLE);
                }
            }
        });
    }
 
}


 以上就是 影片直播原始碼,AndroidStudio登入頁面的切換,更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2988166/,如需轉載,請註明出處,否則將追究法律責任。

相關文章