第三次作业

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     xmlns:app="http://schemas.android.com/apk/res-auto"
 5     xmlns:tools="http://schemas.android.com/tools"
 6     android:layout_width="match_parent"
 7     android:layout_height="match_parent"
 8     android:background="#009688"
 9     tools:context=".MainActivity">
10     <Button
11         android:id="@+id/button"
12         android:layout_width="match_parent"
13         android:layout_height="wrap_content"
14         android:layout_marginLeft="20dp"
15         android:layout_marginRight="20dp"
16         android:text="登录"
17         android:textSize="30dp"
18         android:textColor="#FCF8F7"
19         android:background="#2196F3"
20         tools:layout_editor_absoluteX="165dp"
21         tools:layout_editor_absoluteY="224dp"
22         android:layout_centerHorizontal="true"
23         android:layout_centerVertical="true"
24         android:onClick="qq"
25         />
26 
27     <LinearLayout
28         android:layout_width="match_parent"
29         android:layout_height="wrap_content"
30         android:layout_below="@+id/imageView"
31         android:layout_marginTop="90dp"
32         android:background="#FFFFFF"
33         android:orientation="horizontal">
34 
35         <TextView
36             android:layout_width="wrap_content"
37             android:layout_height="wrap_content"
38             android:text="密码:" />
39 
40         <EditText
41             android:id="@+id/mima"
42             android:layout_width="match_parent"
43             android:layout_height="wrap_content"
44             android:hint="输入密码"
45             android:textColorHint="#1CB9B3"
46 
47 
48             android:layout_marginLeft="20dp" />
49     </LinearLayout>
50     <LinearLayout
51         android:layout_width="match_parent"
52         android:layout_height="wrap_content"
53         android:layout_below="@+id/imageView"
54         android:layout_marginTop="30dp"
55         android:background="#FFFFFF"
56         android:orientation="horizontal">
57 
58         <TextView
59             android:layout_width="wrap_content"
60             android:layout_height="wrap_content"
61             android:text="账号:" />
62 
63         <EditText
64             android:id="@+id/zh"
65             android:layout_width="match_parent"
66             android:layout_height="wrap_content"
67             android:hint="输入账号"
68             android:textColorHint="#358691"
69 
70             android:layout_marginLeft="20dp" />
71     </LinearLayout>
72     <ImageView
73         android:id="@+id/imageView"
74         android:layout_width="80dp"
75         android:layout_height="80dp"
76         android:layout_marginTop="50dp"
77         android:layout_centerHorizontal="true"
78         app:srcCompat="@drawable/ty" />
79 
80 </RelativeLayout>
package com.example.m;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    EditText zh;
    EditText mima;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        zh=findViewById(R.id.zh);
        mima=findViewById(R.id.mima);
    }

    public void qq(View view) {
        String z=zh.getText().toString();
        String m=mima.getText().toString();
        if (z.equals("1234")){
            if (m.equals("1234")){

                Toast.makeText(MainActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();
            }else {

                Toast.makeText(MainActivity.this,"密码错误",Toast.LENGTH_SHORT).show();

            }

        }else{

            Toast.makeText(MainActivity.this,"登陆失败",Toast.LENGTH_SHORT).show();
        }


    }
}

  

posted @ 2019-09-09 14:36  WOJIAOSHENME  阅读(97)  评论(0编辑  收藏  举报