一、新建一个空的LoginActivity
二、在activity.login.xml中进行布局设计
(一)那么如何打开呢这个.xml文件呢?
新建activity后里面会有初始代码,按住Ctrl键点击activity.login就可以进入xml文件了。
(二)如何进行登录界面的布局设计呢?
首先把这个xml改成线性布局,把这个改成LinearLayout。
然后进行布局界面设计
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"> android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> 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="登录系统"/> android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> android:textSize="25sp" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@color/black" android:text="用户名"/> android:id="@+id/login_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" > android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> android:layout_width="match_parent" android:layout_height="wrap_content" android:text="密码" android:textColor="@color/black" android:textSize="25sp" /> android:id="@+id/login_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword"> android:layout_marginTop="15dp" android:gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">
布局界面展示
三、点击进行页面进行跳转
(一)新建一个注册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);
}
});
}
}
狗头三连 ~~~~~~~~~~~~~~~~~~~
发表评论