<?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
首先呢,咱们得先有个跳转后的主页面和注册页面,这里为了方便演示,就简单整个注册页面和主页面吧!狗头保命
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);
}
});
}
}
狗头三连 ~~~~~~~~~~~~~~~~~~~
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)