当前位置:网站首页>Android instance - simple login layout

Android instance - simple login layout

2020-11-09 17:46:43 ZHAO_JH

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#36A4D9"
    android:fitsSystemWindows="false"
    android:gravity="center|top"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <!--     The notice column should be left blank to be transparent -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:textSize="30sp">
    </TextView>
    <!-- title -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:gravity="center"
        android:text=" Easy login page "
        android:textColor="#fff"
        android:textSize="30sp">
    </TextView>
    <!--     User name and password information -->
    <RelativeLayout
        android:layout_width="356dp"
        android:layout_height="300dp"
        android:background="#fff">
        <!--     User name information -->
        <TextView
            android:id="@+id/user_text"
            android:layout_width="96dp"
            android:layout_height="50dp"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="50dp"
            android:background="#36A4D9"
            android:gravity="center"
            android:text=" user name :"
            android:textColor="#fff"
            android:textSize="20sp">
        </TextView>

        <EditText
            android:id="@+id/user_info"
            android:layout_width="203dp"
            android:layout_height="50dp"
            android:layout_marginTop="50dp"
            android:layout_toRightOf="@id/user_text"
            android:hint=" Please enter a user name ">
        </EditText>
        <!--     Password information -->
        <TextView
            android:id="@+id/pwd_text"
            android:layout_width="96dp"
            android:layout_height="50dp"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="110dp"
            android:background="#36A4D9"
            android:gravity="center"
            android:text=" The secret      code :"
            android:textColor="#fff"
            android:textSize="20sp">
        </TextView>

        <EditText
            android:id="@+id/pwd_info"
            android:layout_width="203dp"
            android:layout_height="50dp"
            android:layout_marginTop="110dp"
            android:layout_toRightOf="@id/user_text"
            android:hint=" Please input a password ">
        </EditText>
        <!--         Remember the password -->
        <CheckBox
            android:id="@+id/remember_info"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="170dp"
            android:text=" Remember the username and password "
            android:textColor="#000"
            android:textSize="16sp">
        </CheckBox>
        <!--         The login button -->
        <Button
            android:id="@+id/login_button"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="230dp"
            android:background="#36A4D9"
            android:text=" deng      record "
            android:textColor="#fff"
            android:textSize="26sp">
        </Button>
    </RelativeLayout>
    <!--     Copyright notice information -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        android:layout_weight="1"
        android:gravity="center|bottom"
        android:text="* This application is a personal test , Not to publish without permission *"
        android:textColor="#fff"
        android:textSize="14sp">
    </TextView>
</LinearLayout>

MainActivity.java

package com.example.myapplication;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.app.Activity;
import android.view.*;
import android.widget.*;



public class MainActivity extends Activity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //  preservation Activity The state of   11
        super.onCreate(savedInstanceState);
        //  Load view 
        setContentView(R.layout.activity_main);

        //  Android immersive setting transparent status bar 
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.setNavigationBarColor(Color.TRANSPARENT);
        }
        else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        //  Get button object 
        Button btnshow = findViewById(R.id.login_button);
        // Write it directly this The binding event 
        btnshow.setOnClickListener(this);
    }

    //  Click button method 
    @Override
    public void onClick(View v) {
        //  Get login page data object 
        EditText user_obj = findViewById(R.id.user_info);
        EditText pwd_obj = findViewById(R.id.pwd_info);
        CheckBox remember_obj = findViewById(R.id.remember_info);

        Toast.makeText(getApplicationContext(), " The user name you entered is :【"+user_obj.getText() + "】 The password is :【"+pwd_obj.getText()+"】 Remember the password 【"+remember_obj.isChecked()+"】" , Toast.LENGTH_SHORT).show();
    }
}

版权声明
本文为[ZHAO_JH]所创,转载请带上原文链接,感谢