首页 > 其他分享 >android实现登录注册界面

android实现登录注册界面

时间:2022-10-21 21:58:07浏览次数:51  
标签:界面 登录 Intent import android main intent View

  1. 创建一个androidstudio工程
  • drawable中添加

main_left:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
        <stroke
            android:width="1dp"
            android:color="@color/orange">

        </stroke>
    <corners
        android:bottomLeftRadius="20dp"
        android:topLeftRadius="20dp">

    </corners>
</shape>

main_right:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
        <stroke
            android:width="1dp"
            android:color="@color/orange">

        </stroke>
    <corners
        android:bottomRightRadius="20dp"
        android:topRightRadius="20dp">

    </corners>
</shape>
  • activity_main中完成基本布局代码

    ``

<TextView
    android:id="@+id/tv_mian_1"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:text="登录界面"
    android:gravity="center"
    android:textSize="30sp"
    android:background="#ff8f03"
    android:layout_margin="20dp"/>
<EditText
    android:id="@+id/et_username1"
    android:layout_width="300dp"
    android:layout_height="50dp"
    android:hint="用户名"
    android:textSize="18sp"
    android:textColor="@color/black"
    android:layout_margin="30dp" />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
<EditText
    android:id="@+id/et_password1"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:hint="密 码"
    android:textSize="18sp"
    android:textColor="@color/black"
    android:layout_marginLeft="30dp"
    android:inputType="textPassword"/>

    <ImageView
        android:layout_width="20dp"
        android:id="@+id/eye"
        android:layout_height="20dp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="20dp"
        />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <Button
        android:id="@+id/btn_main_1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="登录"
        android:background="@drawable/main_left"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="5dp"
        />
    <Button
        android:id="@+id/btn_main_2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="注册"
        android:background="@drawable/main_right"
        android:layout_marginRight="50dp"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="5dp"
        />
</LinearLayout>
``
  1. 完成登录后界面和注册时界面
  • activity_login
<?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"
    tools:context=".LoginActivity"
    android:orientation="vertical"
    android:padding="10dp">

    <TextView
        android:id="@+id/tv_login_1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:text="登录后界面"
        android:gravity="center"
        android:textSize="30sp"
        android:background="#feeeee"
        android:layout_margin="20dp"/>

</LinearLayout>
  • activity_register
<?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"
    tools:context=".RegisterActivity"
    android:orientation="vertical"
    android:padding="10dp">

    <TextView
        android:id="@+id/tv_register_1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:text="注册界面"
        android:gravity="center"
        android:textSize="30sp"
        android:background="#ff8ff3"
        android:layout_margin="20dp"/>
    <EditText
        android:id="@+id/et_register_1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="用户名"
        android:textSize="18sp"
        android:textColor="@color/black"
        android:layout_margin="20dp" />
    <EditText
        android:id="@+id/et_register_2"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="设置密码"
        android:textSize="18sp"
        android:textColor="@color/black"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:inputType="textPassword"/>
    <EditText
        android:id="@+id/et_register_3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:hint="确认密码"
        android:textSize="18sp"
        android:textColor="@color/black"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:inputType="textPassword"
        android:layout_marginTop="20dp"/>



        <Button
            android:id="@+id/btn_register_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="提交"
            android:layout_marginTop="20dp"
            />



</LinearLayout>
  1. 其次完成MainActivity和RegisterActivity的代码
  • 先在网上下载两个小眼睛完成输入密码后点击后查看密码插入到res-mipmap

  • MainActivity
```
package com.example.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.text.method.TransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    //声明控件
    private Button mBtn_main_1;
    private Button mBtn_main_2;
    private EditText mEt_username1;
    private EditText mEt_password1;
    private Object vi;
    private boolean hide = true;
    private ImageView eye;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //找到控件
       mBtn_main_1 = findViewById(R.id.btn_main_1);
        mBtn_main_2 = findViewById(R.id.btn_main_2);
        mEt_username1 = findViewById(R.id.et_username1);
        mEt_password1 = findViewById(R.id.et_password1);
        eye = findViewById(R.id.eye);
        eye.setImageResource(R.mipmap.close);
        eye.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    switch (view.getId()) {
                            case R.id.eye:
                                if (hide == true) {
                                    eye.setImageResource(R.mipmap.open);
                                    HideReturnsTransformationMethod method = HideReturnsTransformationMethod.getInstance();

                                    mEt_password1.setTransformationMethod(method);
                                    boolean b = hide == false;
                                } else {
                                    eye.setImageResource(R.mipmap.close);
                                    TransformationMethod method = PasswordTransformationMethod.getInstance();
                                    mEt_password1.setTransformationMethod(method);
                                    boolean b = hide == true;
                                }
                                int index = mEt_password1.getText().toString().length();
                                mEt_password1.setSelection(index);
                                break;
                        }
                    }
        });

        /*mBtn_main_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this,LoginActivity.class);
                startActivity(intent);
            }
        });*/
        mBtn_main_1.setOnClickListener(this);
        mBtn_main_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this,RegisterActivity.class);


                startActivity(intent);
            }
        });



    }


    public void onClick(View view) {
        //从RegisterActivity中带过来的用户名和密码
        Intent intent = getIntent();
        String name = intent.getStringExtra("username");
        String pass = intent.getStringExtra("password");
        //从本界面activity_main中获取输入的用户名和密码
        String username1 = mEt_username1.getText().toString();
        String password1 = mEt_password1.getText().toString();
        Intent intent1 = null;
        if (username1.equals(name) && password1.equals(pass)){
            intent1 = new Intent(MainActivity.this,LoginActivity.class);
            startActivity(intent1);
        }else {

        }
    }
}
```
  • RegisterACtivity
package com.example.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class RegisterActivity extends AppCompatActivity {
    private Button mBtn_register_1;



    @SuppressLint("MissingInflatedId")

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        mBtn_register_1 = findViewById(R.id.btn_register_1);
        mBtn_register_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
                //利用方法生成用户名和密码
                intent.putExtra("username","abc");
                intent.putExtra("password","12");
                startActivity(intent);
            }
        });
    }
}

标签:界面,登录,Intent,import,android,main,intent,View
From: https://www.cnblogs.com/LLever/p/16814893.html

相关文章

  • 某某某某招某某某 网站js登录加密方式。
    1.135分析后为AES加密。加密流程constCryptoJS=require('crypto-js');//引用AES源码jsconste=JSON.parse('{"data":{"password":"123456"},"key":"pigxpigxpi......
  • Android 增加一个应用启动界面
    为了让app的逼格更高 为了让app的界面更人性化,并且让app在刚刚启动数据还没加载出来时不至于一片白屏太难看以至于吓跑用户,尝试增加一个启动页面。 首先建立一个新的......
  • Android 软键盘删除键触发问题分享
    本文解决的问题:Android输入法软键盘删除键点击多次,只触发一次删除事件本文示例代码地址:Android软键盘删除键触发示例代码背景笔者维护的app功能中,有个图文编辑器,由......
  • #Android studio 微信页面制作(二)
    今天继续用Androidstudio实现微信页面的制作首先打开项目看看之前的进展。这里我在第一次制作的基础上,使用recycleview等控件对联系录页面进行了新的UI设计布局。本次......
  • android有声电子书新版本1.61发布
    有声电子书(适用于Android1.5及以上版本)软件支持格式为txt,umd,jpg文字及漫画书的阅读,提供用户搜索SD卡中所有图书。特别加入了文本直接转换成语音的有声阅读功能。......
  • Android软件中嵌入地图之一:Sogou地图
          在App中加入地图功能真是让人揪结,Google地图功能强大,但是有些国内的手机厂商去掉了手机系统中Google地图的相关库,所以这类机型将无法安装调用了Google地图的软......
  • Android 代码库
    -​​安卓巴士​​-​​Arsenal​​-​​AndroidLibraries​​-​​Gems​​-​​Appance​​-​​Devstore​​-​​android-nice-repo​​-​​apkdemo​......
  • android异步任务 访问网络 加载图片 解决方案大集合
    1.Handler+Thread异步执行任务在UI线程中开启子线程,使用Handler发消息,通知主线程更新UI​直接在UI线程中开启子线程来更新TextView显示的内容,运行程序我们会发现,如下......
  • Android 学习导航
    -​​android-open-project(Trinea)​​-​​android-open-project-demo(开源项目Demo)​​-​​MaterialDesign(Material案例大全)​​-​​awesome-android-ui​​......
  • JDBC练习_登录案例和JDBC事务管理
    JDBC练习_登录案例练习:需求:1.通过键盘录入用户名和密码  2.判断用户是否登录成功"select*fromuserwhereusername="" andpassword="......