登录页面Android-项目二

Activity_ZSButton.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="请输入用户名:"
        android:textSize="30sp"
        android:textColor="#030303"
        android:textStyle="bold"
        android:layout_marginTop="10dp"/>
    <EditText
        android:id="@+id/editText_inputname"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="用户名:"
        android:textStyle="bold" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="请输入密码:"
        android:textSize="30sp"
        android:textColor="#030303"
        android:textStyle="bold"
        android:layout_marginTop="10dp"/>
    <EditText
        android:id="@+id/editText_inputpwd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="密 码:"
        android:inputType="textPassword"
        android:textStyle="bold" />
    <Button
        android:id="@+id/button_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        android:textSize="30sp"
        android:textColor="#000000"
        android:textStyle="bold"
        android:layout_marginTop="10dp" />
    <Button
        android:id="@+id/button_cancle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="取消"
        android:textSize="30sp"
        android:textColor="#000000"
        android:textStyle="bold"
        android:layout_marginTop="10dp" />
    <TextView
        android:id="@+id/textView_display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="显示获取的用户名和密码"
        android:textSize="20sp"
        android:textColor="#0E0D0E"
        android:textStyle="bold"
        android:layout_marginTop="10dp"
        android:visibility="gone"/>

</LinearLayout>

ZSButtonActivity.java

package com.example.zsbutton;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    private EditText edit_name,edit_pwd;
    private Button btn_login,btn_cancle;
    private TextView txt_display;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        edit_name=findViewById(R.id.editText_inputname);
        edit_pwd=findViewById(R.id.editText_inputpwd);
        btn_login = findViewById(R.id.button_login);
        btn_cancle = findViewById(R.id.button_cancle);
        txt_display = findViewById(R.id.textView_display);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String strname = edit_name.getText().toString();
                String strpwd = edit_pwd.getText().toString();
                txt_display.setVisibility(View.VISIBLE);
                txt_display.setText("哈哈,我偷偷地盗取了你的秘密信息\\n用户名为:\"+strname + \"\\n 密码为:\" +strpwd");
            }
        });
        btn_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                txt_display.setVisibility(View.GONE);
                edit_name.setText("");
                edit_pwd.setText("");
            }
        });
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值