Android-2

应用登陆界面代码

package com.example.homework2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button blogin = (Button)findViewById(R.id.enter);//先引用组件,然后执行算法
        blogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String user = "zhangsan";
                String password = "123456";
                EditText u = (EditText)findViewById(R.id.etname);
                EditText p = (EditText)findViewById(R.id.etpass);
                if (u.getText().toString().equals(user)){//判断用户名是否正确
                    //读取文本信息,转为字符串,判断正确
                    if (p.getText().toString().equals(password)){
                        Toast.makeText(MainActivity.this, "登陆成功", Toast.LENGTH_LONG).show();
                    }else{
                        //密码输入错误
                        Toast.makeText(MainActivity.this, "密码错误", Toast.LENGTH_LONG).show();
                    }
                }else{
                    //用户名错误提示
                    Toast.makeText(MainActivity.this, "用户名错误", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}

代码未实现记住密码与忘记密码选项,初始用户名为:zhangsan,初始密码为:123456.

代码运行截图

Android-2

 

 Component Tree 截图

Android-2

 

Android-2

上一篇:Appium for mac环境


下一篇:ICPC Northeastern European Regional Contest 2019 Apprentice Learning Trajectory