android studio 登录界面

 XML界面:

<?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"
    android:padding="15dp"
    tools:context=".EditTextActivity">

    <EditText  
        android:id="@+id/yonghu"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/bt_5"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:drawableLeft="@drawable/ic_home_black_24dp"
        android:drawablePadding="5dp"
        android:hint="用户名"
        android:maxLines="1"
        android:textColor="#FF000000"
        android:textSize="16sp" />

    <EditText
        android:id="@+id/mima"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/yonghu"
        android:layout_marginTop="15dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:drawableLeft="@drawable/ic_dashboard_black_24dp"
        android:drawablePadding="5dp"
        android:hint="密码"
        android:inputType="textPassword"
        android:textColor="#FF000000"
        android:textSize="16sp"
        android:background="@drawable/bt_5"
        android:maxLines="1" />
    <RadioGroup
        android:id="@+id/radiogroup"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/mima">
        <RadioButton
            android:layout_margin="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="学生"
            android:textSize="20dp">
        </RadioButton>
        <RadioButton
            android:layout_margin="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="老师"
            android:textSize="20dp">
        </RadioButton>
        <RadioButton
            android:layout_margin="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="游客"
            android:textSize="20dp">
        </RadioButton>
    </RadioGroup>
    <CheckBox
        android:checked="true"
        android:layout_margin="10dp"
        android:id="@+id/xxwy"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/linerdenglu"
        android:text="学习委员"
        android:textSize="25dp">
    </CheckBox>

    <LinearLayout
        android:id="@+id/linerdenglu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@id/radiogroup">

        <Button
            android:id="@+id/denglu"
            android:layout_weight="1"
            android:layout_margin="15dp"
            android:layout_width="match_parent"
            android:padding="5dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/mima"
            android:layout_marginTop="10dp"
            android:background="@color/blue"
            android:text="登录"
            android:textColor="#fff"
            android:textSize="20dp">

        </Button>
        <Button
            android:id="@+id/zhuce"
            android:layout_weight="1"
            android:layout_margin="15dp"
            android:layout_width="match_parent"
            android:padding="5dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/mima"
            android:layout_marginTop="10dp"
            android:background="@color/blue"
            android:text="注册"
            android:textColor="#fff"
            android:textSize="20dp">

        </Button>
    </LinearLayout>
</RelativeLayout>

效果图:

 

java逻辑界面:

可以采用if()else语句:

package com.example.myapplication3;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class EditTextActivity extends AppCompatActivity {
    private EditText user; //用户输入框
    private EditText mm; //密码输入框
    private Button mbdenglu; //登录按钮

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_text);
     //寻找对应XMl文件的对应ID,并设立事件监听
        user=(EditText) findViewById(R.id.yonghu);
        user.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                Log.d("username",charSequence.toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

        mm=(EditText) findViewById(R.id.mima);
        mm.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                Log.d("password", charSequence.toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

//寻找对应XMl文件的对应ID,并设立登录按钮事件监听

        mbdenglu=(Button) findViewById(R.id.denglu);
        mbdenglu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String    username=user.getText().toString();
                String    password=mm.getText().toString();

//登录和密码设置,此处我设置为空

                if (username.equals("")&&password.equals("")){
                    //走请求接口,传用户名和密码
                    //请求成功
                    Toast.makeText(EditTextActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
                    //页面跳转....
                    Intent intent = new Intent(EditTextActivity.this, MainActivity.class);
                    startActivity(intent);
                }else if (username.equals("")&&password.equals("")){
                    Toast.makeText(EditTextActivity.this, "请输入用户名和密码", Toast.LENGTH_SHORT).show();
                }else if (username!=null&&password.equals("")){
                    Toast.makeText(EditTextActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
                }else if(username.equals("")&&password!=null){
                    Toast.makeText(EditTextActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(EditTextActivity.this, "请输入正确的用户名和密码", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}

 checkbox按钮和注册界面我没有写事件监听。

登录逻辑采用简单的if语句获取数据,可以equal输入你想要设置的账户密码。

觉得不错,给个关注吧!

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值