AndroidStudio创建手机登录注册跳转界面

AndroidStudio创建手机登录注册跳转界面,第1张

一、新建一个空的LoginActivity

二、在activity.login.xml中进行布局设计 (一)那么如何打开呢这个.xml文件呢? 新建activity后里面会有初始代码,按住Ctrl键点击activity.login就可以进入xml文件了。

(二)如何进行登录界面的布局设计呢? 首先把这个xml改成线性布局,把这个改成LinearLayout。

然后进行布局界面设计
<?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="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:background="@color/white"
    android:orientation="vertical"
    tools:context=".LoginActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/purple_200"
        android:textSize="40dp"
        android:background="@color/white"
        android:gravity="center"
        android:text="登录系统"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:textSize="25sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:text="用户名"/>
    </LinearLayout>

    <EditText
        android:id="@+id/login_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        >
    </EditText>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="密码"
            android:textColor="@color/black"
            android:textSize="25sp" />
    </LinearLayout>

    <EditText
        android:id="@+id/login_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword">
    </EditText>

    <LinearLayout
        android:layout_marginTop="15dp"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <Button
            android:id="@+id/login_btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="登录">
        </Button>
        <Button
            android:id="@+id/reg_btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="注册">
        </Button>
    </LinearLayout>

</LinearLayout>
布局界面展示

三、点击进行页面进行跳转 (一)新建一个注册activity与主页面activity 首先呢,咱们得先有个跳转后的主页面和注册页面,这里为了方便演示,就简单整个注册页面和主页面吧!狗头保命


(二)分别在这俩布局里面随便写点标识的东西


(三)在LoginActivity中用Intent对其实现跳转
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        Button button = findViewById(R.id.login_btn);
        Button button1 = findViewById(R.id.reg_btn);

        EditText e_username = findViewById(R.id.login_name);
        EditText e_password = findViewById(R.id.login_password);
        String username = e_username.getText().toString();
        String password = e_password.getText().toString();

        //点击登录按钮,实现跳转
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(LoginActivity.this,username,Toast.LENGTH_SHORT);
                Toast.makeText(LoginActivity.this,password,Toast.LENGTH_SHORT);
                Intent intent = new Intent(LoginActivity.this,HomeActivity.class);
                startActivity(intent);
            }
        });
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this,RestActivity.class);
                startActivity(intent);
            }
        });
    }
}
狗头三连 ~~~~~~~~~~~~~~~~~~~

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1369960.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-15
下一篇 2022-06-15

发表评论

登录后才能评论

评论列表(0条)

保存