![]()
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
tools:context=".MainActivity"
android:background="#ECE4E4"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="80sp"
android:layout_height="80sp"
android:layout_centerHorizontal="true"
android:layout_marginTop="100sp"
app:srcCompat="@mipmap/ic_launcher" />
<LinearLayout
android:id="@+id/lzh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:orientation="horizontal">
<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="账号:"
android:textSize="10sp"
android:textStyle="bold" />
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="10dp">
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/mm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lzh"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:orientation="horizontal">
<TextView
android:id="@+id/pw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="密码"
android:textSize="10sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:password="true"
android:id="@+id/et2"
android:padding="10dp"
android:background="#FFFFFF">
</EditText>
</LinearLayout>
<Button
android:id="@+id/qr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:background="#2196F3"
android:layout_below="@+id/mm"
android:layout_marginTop="60dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:onClick="denglu"
/>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/qr"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text=""
android:textColor="#F44336"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText zh;
EditText mm;
TextView ts;
Button dl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
zh=(EditText) findViewById(R.id.et1);
mm=(EditText) findViewById(R.id.et2);
dl=(Button) findViewById(R.id.qr);
ts=(TextView) findViewById(R.id.tv);
}
public void denglu(View view){
String z=zh.getText().toString();
String m=mm.getText().toString();
if (z.equals(m)){
Toast.makeText(MainActivity.this, "登陆成功",Toast.LENGTH_SHORT ).show();
}else {
ts.setText("登录失败");
startActivity(new Intent(this, MainActivity.class));
finish();
overridePendingTransition(0,0);
}
}
}