作业三

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:background="#03A9F4">
    <ImageView
            android:id="@+id/imageView"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="100dp"
            app:srcCompat="@mipmap/ic_launcher" />

    <LinearLayout
            android:background="#FDFCFC"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageView"
            android:layout_marginTop="10dp"
    >
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/btn"
                android:text=""

        />
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="账号"
                android:textSize="20dp"
        />
        <EditText
                android:id="@+id/zh"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
            android:background="#FDFCFC"
            android:id="@+id/m"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageView"
            android:layout_marginTop="60dp"

    >
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密码"
                android:textSize="20dp"
        />
        <EditText
                android:id="@+id/mm"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    </LinearLayout>

    <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#9C27B0"
            android:layout_below="@+id/m"
            android:layout_marginTop="50dp"
            android:layout_centerHorizontal="true"
            android:text="登陆"
            android:onClick="CCC"
    />
</RelativeLayout>
package com.example.myapplication3;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    EditText et1;
    EditText et2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        et1 = findViewById(R.id.zh);
        et2 = findViewById(R.id.mm);
    }
    public void CCC(View view) {
        String t1=et1.getText().toString();
        String t2=et2.getText().toString();

        if (t1.equals(t2)) {

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

        }


    }
}

 

posted @ 2019-09-09 16:50  逝*无痕  阅读(82)  评论(0)    收藏  举报