1 ?xml version="1.0" encoding="utf-8"?>
2 <RelativeLayout 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 tools:context=".MainActivityzuoye2"
8 android:background="#ECE4E4"
9 >
10
11 <ImageView
12 android:id="@+id/imageView"
13 android:layout_width="80sp"
14 android:layout_height="80sp"
15 app:srcCompat="@drawable/logo"
16 android:layout_centerHorizontal="true"
17 android:layout_marginTop="100sp"
18 />
19 <LinearLayout
20 android:id="@+id/lzh"
21 android:layout_width="match_parent"
22 android:layout_height="wrap_content"
23 android:layout_below="@+id/imageView"
24 android:layout_marginTop="50dp"
25 android:background="#FFFFFF"
26 android:layout_marginLeft="20sp"
27 android:layout_marginRight="20sp"
28 android:orientation="horizontal">
29 <TextView
30 android:id="@+id/tv1"
31 android:layout_width="wrap_content"
32 android:layout_height="wrap_content"
33 android:padding="15dp"
34 android:text="账号"
35 android:textStyle="bold"
36 android:textSize="20dp"></TextView>
37 <EditText
38 android:id="@+id/et1"
39 android:layout_width="match_parent"
40 android:layout_height="match_parent"
41 android:background="#FFFFFF"
42 android:padding="10dp">
43
44 </EditText>
45 </LinearLayout>
46
47
48 <LinearLayout
49 android:id="@+id/mm"
50 android:layout_width="match_parent"
51 android:layout_height="wrap_content"
52 android:layout_below="@+id/lzh"
53 android:layout_marginTop="50dp"
54 android:background="#FFFFFF"
55 android:layout_marginLeft="20sp"
56 android:layout_marginRight="20sp"
57 android:orientation="horizontal">
58
59 <TextView
60 android:id="@+id/pw"
61 android:layout_width="wrap_content"
62 android:layout_height="wrap_content"
63 android:padding="15dp"
64 android:text="密码:"
65 android:textStyle="bold"
66 android:textSize="20sp" />
67 <EditText
68 android:layout_width="match_parent"
69 android:layout_height="match_parent"
70 android:password="true"
71 android:id="@+id/et2"
72 android:padding="10dp"
73 android:background="#FFFFFF">
74
75 </EditText>
76 </LinearLayout>
77 <Button
78 android:id="@+id/qr"
79 android:layout_width="match_parent"
80 android:layout_height="wrap_content"
81 android:text="登录"
82 android:textStyle="bold"
83 android:textColor="#FFFFFF"
84 android:textSize="30sp"
85 android:background="#2196F3"
86 android:layout_below="@+id/mm"
87 android:layout_marginTop="60dp"
88 android:layout_marginLeft="40dp"
89 android:layout_marginRight="40dp"
90 android:onClick="denglu"
91 tools:ignore="OnClick" />
92
93 <TextView
94 android:id="@+id/tv"
95 android:layout_width="wrap_content"
96 android:layout_height="wrap_content"
97 android:layout_below="@+id/qr"
98 android:layout_centerHorizontal="true"
99 android:layout_marginTop="50dp"
100 android:text=""
101 android:textColor="#F44336"
102 android:textSize="20sp"
103 android:textStyle="bold" />
104
105 </RelativeLayout>
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:app="http://schemas.android.com/apk/res-auto"
3 xmlns:tools="http://schemas.android.com/tools"
4 android:layout_width="match_parent"
5 android:layout_height="match_parent"
6 tools:context=".MainActivity2">
7
8 <TextView
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:layout_above="@+id/zh"
12 android:layout_marginStart="40dp"
13 android:layout_marginLeft="40dp"
14 android:layout_marginTop="40dp"
15 android:layout_marginBottom="40dp"
16 android:text="welcome to Wechat"
17 android:textSize="40sp">
18
19 </TextView>
20 <LinearLayout
21 android:id="@+id/zh"
22 android:layout_width="match_parent"
23 android:layout_height="wrap_content"
24 android:orientation="horizontal"
25 android:layout_centerHorizontal="true"
26 android:layout_centerVertical="true"
27 android:layout_marginLeft="20sp"
28 android:layout_marginRight="20sp">
29 <TextView
30 android:id="@+id/z"
31 android:layout_width="wrap_content"
32 android:layout_height="wrap_content"
33 android:text="你的账号是:"
34 >
35 </TextView>
36 <TextView
37 android:id="@+id/n"
38 android:layout_width="wrap_content"
39 android:layout_height="wrap_content"
40 android:textSize="20sp"
41 android:textColor="#D236B1D6"
42 android:text=""
43 >
44 </TextView>
45 </LinearLayout>
46 <LinearLayout
47 android:layout_width="match_parent"
48 android:layout_height="wrap_content"
49 android:orientation="horizontal"
50 android:layout_marginTop="30sp"
51 android:layout_marginLeft="20sp"
52 android:layout_marginRight="20sp"
53 android:layout_below="@id/zh">
54 <TextView
55 android:id="@+id/mm"
56 android:layout_width="wrap_content"
57 android:layout_height="wrap_content"
58 android:text="你的密码是:"
59 >
60 </TextView>
61 <TextView
62 android:id="@+id/m"
63 android:layout_width="wrap_content"
64 android:layout_height="wrap_content"
65 android:textSize="20sp"
66 android:textColor="#D236B1D6"
67 android:text=""
68 >
69 </TextView>
70 </LinearLayout>
71 </RelativeLayout>
package com.example.zuoye2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Bundle;
public class MainActivityzuoye2 extends AppCompatActivity {
EditText zh;
EditText mm;
TextView ts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activityzuoye2);
zh=(EditText) findViewById(R.id.et1);
mm=(EditText) findViewById(R.id.et2);
}
public void denglu(View view) {
String z=zh.getText().toString();
String m=mm.getText().toString();
if (z.equals(m)){
Intent intent=new Intent();
intent.setClass(MainActivityzuoye2.this,MainActivityzuoye2.class);
intent.putExtra("123456",z);
intent.putExtra("789",m);
startActivity(intent);
Toast.makeText(MainActivityzuoye2.this, "登陆成功",Toast.LENGTH_SHORT ).show();
}else {
Toast.makeText(MainActivityzuoye2.this, "登陆失败",Toast.LENGTH_SHORT ).show();
finish();
overridePendingTransition(0,0);
}
}
}
1 package com.example.zuoye2;
2
3 import androidx.appcompat.app.AppCompatActivity;
4
5 import android.os.Bundle;
6 import android.content.Intent;
7 import android.os.Bundle;
8 import android.widget.TextView;
9
10 public class MainActivity2 extends AppCompatActivity {
11
12 @Override
13 protected void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState);
15 setContentView(R.layout.activity_main2);
16 Intent intent=getIntent();
17 String nam=intent.getStringExtra("123456");
18 String mm=intent.getStringExtra("789");
19 TextView na=(TextView)findViewById(R.id.n);
20 TextView mi=(TextView)findViewById(R.id.m);
21 na.setText(nam);
22 mi.setText(mm);
23 }
24 }