android 学习(家庭记账本的开发 2)

今天写了软件的登录界面,明天准备添加功能

 1 package com.example.homework;
 2 
 3 import androidx.appcompat.app.AppCompatActivity;
 4 
 5 import android.content.Intent;
 6 import android.os.Bundle;
 7 import android.view.View;
 8 import android.widget.Toast;
 9 
10 public class MainActivity extends AppCompatActivity implements View.OnClickListener {
11 
12     @Override
13     protected void onCreate(Bundle savedInstanceState) {
14         super.onCreate(savedInstanceState);
15         setContentView(R.layout.activity_main);
16         initUI();
17     }
18 
19     private void initUI() {
20         findViewById(R.id.button1).setOnClickListener(this);
21         findViewById(R.id.button2).setOnClickListener(this);
22     }
23 
24     @Override
25     public void onClick(View v) {
26         switch (v.getId()){
27             case R.id.button1://执行按钮1
28                 Intent intent =new Intent();
29                 intent.setClass(getApplicationContext(), FirstActivity.class);
30                 this.startActivity(intent);
31                 break;
32             case R.id.button2:
33                 Intent intent2 =new Intent();
34                 intent2.setClass(getApplicationContext(), secondActivity.class);
35                 this.startActivity(intent2);
36                 break;
37 
38         }
39 
40     }
41 }
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     tools:context=".MainActivity">
 9 
10     <TextView
11         android:layout_width="wrap_content"
12         android:layout_height="46dp"
13         android:text="用户名:"
14         android:textSize="30dp" />
15 
16     <EditText
17         android:id="@+id/edit_1"
18         android:layout_width="match_parent"
19         android:layout_height="55dp"
20         android:hint="请填写用户名"/>
21 
22 
23     <TextView
24         android:layout_width="wrap_content"
25         android:layout_height="46dp"
26         android:text="密码:"
27         android:textSize="30dp" />
28 
29     <EditText
30         android:id="@+id/edit_2"
31         android:layout_width="match_parent"
32         android:layout_height="55dp"
33         android:hint="请输入密码"/>
34 
35 
36     <Button
37         android:id="@+id/button1"
38         android:layout_width="match_parent"
39         android:layout_height="60dp"
40         android:text="登录" />
41 
42     <Button
43         android:id="@+id/button2"
44         android:layout_width="match_parent"
45         android:layout_height="60dp"
46         android:text="注册" />
47 
48 </LinearLayout>
原文地址:https://www.cnblogs.com/Nojava/p/14907137.html