Android studio 用户登录界面设计

acrivity_main.xml

// acrivity_main.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="com.example.uitest.MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="用户名:"
            android:textSize="30sp"
            android:textColor="#a5c1c0"
            android:layout_weight="1"/>
        <EditText
            android:id="@+id/edit_userName"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="请输入用户名"
            android:textSize="30sp"
            android:textColor="#a5c1c0"
            android:layout_weight="2"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="密    码:"
            android:textSize="30sp"
            android:textColor="#C0FF3E"
            android:layout_weight="1"/>
        <EditText
            android:id="@+id/edit_password"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="请输入密码"
            android:textSize="30sp"
            android:textColor="#C0FF3E"
            android:layout_weight="2"/>
    </LinearLayout>
    <Button
        android:id="@+id/login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        android:textAllCaps="false"
        android:textColor="#08ee00"
        android:textSize="30sp"
        android:background="@color/colorback"
        />
</LinearLayout>

activity_server.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.example.uitest.ServerActivity">
<TextView
    android:id="@+id/textLoginData"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="#FFF166"
    android:textSize="30sp"/>
</android.support.constraint.ConstraintLayout>

ServerActivity.java

package com.example.uitest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class ServerActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_server);
        TextView textView=findViewById(R.id.textLoginData);
        Intent intent=getIntent();
        String userName=intent.getStringExtra("userName");
        String password=intent.getStringExtra("password");
        textView.setText("登录数据"+"用户为:"+userName+"密码为:"+password);
    }
}

MainActivity.java

package com.example.uitest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final EditText editTextUerName=findViewById(R.id.edit_userName);
        final EditText editTextPassword=findViewById(R.id.edit_password);
        Button buttonLogin=findViewById(R.id.login);


        buttonLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userName=editTextUerName.getText().toString();
                String password=editTextPassword.getText().toString();
                String mname="你的名字";
                String mpass="12345678";
                if (userName.equals(mname) && password.equals(mpass)){
                    Intent intent=new Intent(MainActivity.this,ServerActivity.class);
                    intent.putExtra("userName",userName);
                    intent.putExtra("password",password);
                    startActivity(intent);
                    Toast.makeText(MainActivity.this,"登录成功",Toast.LENGTH_LONG).show();
                }else if ("".equals(userName)&&"" .equals(password)){
                    Toast.makeText(MainActivity.this,"用户名或密码不能为空",Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(MainActivity.this,"用户名或密码错误",Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}
  • 0
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值