登录,进入之后选择登录或注册
package com.example.bookkeeping; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initUI(); } private void initUI() { findViewById(R.id.button1).setOnClickListener(this); findViewById(R.id.button2).setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.button1://执行按钮1 Intent intent =new Intent(); intent.setClass(getApplicationContext(), FirstActivity.class); this.startActivity(intent); break; case R.id.button2: Intent intent2 =new Intent(); intent2.setClass(getApplicationContext(), secondActivity.class); this.startActivity(intent2); break; } } }
一个onclick事件可以进行页面的跳转
<?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="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="46dp" android:text="用户名:" android:textSize="30dp" /> <EditText android:id="@+id/edit_1" android:layout_width="match_parent" android:layout_height="55dp" android:hint="请填写用户名"/> <TextView android:layout_width="wrap_content" android:layout_height="46dp" android:text="密码:" android:textSize="30dp" /> <EditText android:id="@+id/edit_2" android:layout_width="match_parent" android:layout_height="55dp" android:hint="请输入密码"/> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="60dp" android:text="登录" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="60dp" android:text="注册" /> </LinearLayout>