• 【Android Studio】简单的QQ登录界面



    注:实验环境 Android studio 2021.2.1

    1、头像设计

    • 首先在layout文件里面选择了RelativeLayout(相对布局)作为整个页面的布局。用下面的属性设置布局中子元素的排列方式为垂直排列;
    android:orientation="vertical"  
    
    • 1
    • 在顶端放置了一个ImageView控件,id设为“iv”,宽度和高度设置的都是70dp。设置为水平居中;
    android:layout_centerHorizontal="true"  
    
    • 1
    • 然后使头像在整个页面下调一点,不要紧贴着顶端,所以layout_marginTop设置为40dp。
      最后选择drawable文件夹中的head文件作为头像。
      在这里插入图片描述

    2、账号输入框

    • 利用LinearLayout(线性布局)作为账号输入框的外层布局,orientation设置的为水平排列。
    • 放置了一个TextView控件,宽度和高度设置的wrap_content,即适应内容大小,显示文本“账号”。紧接着放置一个EditText控件,用于输入账号内容,使用layout_toRightOf属性定位于账号的右侧。
    • 使用android:layout_marginLeft="5dp"和android:padding="10dp"进行微调,margin是外边距,padding是内边距。
      在这里插入图片描述
      3、密码输入框
    • 最外层依旧是LinearLayout(线性布局),整体放置在上一个LinearLayout的下面,控件排列依然为horizontal(水平)。
    • 放置一个TextView文本显示框,文本内容是“密码”,文本颜色为黑色,文本大小为20sp。
      android:background="@null"去除了输入框的背景横线。
    • 再放置一个EditText文本输入框,inputType设置为textPassword,输入时候会隐藏输入内容,使用*** 代替。
      在这里插入图片描述

    4、复选框

    • 在文本框和输入框下面,放置两个复选框,用来显示“自动登录”和"记住密码"这两个选项。另外还有TextView文本显示框,内容为找回密码。
      在这里插入图片描述

    5、登录按钮

    最下面放置一个Button控件,文本内容为“登录”,文本颜色为蓝色,就是用来登录的。
    在这里插入图片描述

    6、设置点击事件

    • 对登录按钮设置了setOnClickListener,即点击事件监听器。
    • 在监听器里面重写了onClick方法,首先获取到输入框中的账号和密码
    • AlertDialog dialog;声明一个对话框对象。
      AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this)初始化该对象。
      .setTitle("账号或密码错误")设置了对话框的标题为。
      .setIcon(R.mipmap.ic_launcher)设置了对话框图标.
      .setMessage("请输入正确的账号和密码")设置了对话框的提示信息。
      (由于这里没有设置登录之后的页面,所以这里将做输入的信息都视作账号或密码错误)
      在这里插入图片描述

    7、总体效果:

    在这里插入图片描述

    源码

    activity_main.xml

    
    <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:background="@drawable/bg"
        android:orientation="vertical">
    
        <ImageView
            android:id='@+id/iv'
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"
            android:background="@drawable/head" />
        <LinearLayout
            android:id="@+id/number_11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/iv"
            android:layout_centerVertical="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="15dp"
            android:background="#ffffff"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/tv_number"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="账号:"
                android:textColor="#000"
                android:textSize="20sp" />
    
            <EditText
                android:id="@+id/et_number"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/tv_number"
                android:layout_marginLeft="5dp"
                android:background="@null"
                android:inputType="text"
                android:textCursorDrawable="@drawable/cursor"
                android:padding="10dp" />
        LinearLayout>
        <LinearLayout
            android:id="@+id/password_11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/number_11"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="#ffffff"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/tv_password"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="密码:"
                android:textColor="#000"
                android:textSize="20sp" />
            <EditText
                android:id="@+id/et_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_toRightOf="@id/tv_password"
                android:background="@null"
                android:inputType="textPassword"
                android:textCursorDrawable="@drawable/cursor"
                android:padding="10dp"/>
        LinearLayout>
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="230dp">
    
    
    
            <CheckBox
                android:id="@+id/checkBox2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/colorAccent"
                android:buttonTint="@color/colorAccent"
                android:text="自动登录" />
    
            <CheckBox
                android:id="@+id/checkBox3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="150dp"
                android:textColor="@color/colorAccent"
                android:buttonTint="@color/colorAccent"
                android:text="记住密码" />
    
            <TextView
                android:id="@+id/tv_register"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="20dp"
                android:layout_marginTop="5dp"
                android:text="找回密码"
                android:textColor="#FFFFFFFF" />
            
    
    
        RelativeLayout>
    
        <Button
            android:id="@+id/btn_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/password_11"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="38dp"
            android:background="#3C8DC4"
            android:text="登录"
            android:textColor="#ffffff"
            android:textSize="20sp" />
    
        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="360dp"
            android:layout_marginLeft="15dp"
            android:text="注册账号"
            android:textColor="#ffffff"/>
    
        <CheckBox
            android:id="@+id/checkBox4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="600dp"
            android:layout_marginLeft="100dp"
            android:buttonTint="@color/colorAccent"
            android:text="我已阅读并同意《隐私政策》"
            android:textColor="@color/colorAccent" />
    RelativeLayout>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150

    MainActivity.java

    package zj.dzh.qq;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class MainActivity extends AppCompatActivity {
        public Button btn;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            btn = (Button) findViewById(R.id.btn_login);//绑定登录按钮
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    android.app.AlertDialog dialog;
                    android.app.AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this)
                            .setTitle("账号或密码错误")                 //设置对话框的标题
                            .setIcon(R.mipmap.ic_launcher)               //设置对话框标题图标
                            .setMessage("请输入正确的账号和密码")                //设置对话框的提示信息
                            //添加"确定"按钮
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();                             //关闭对话框
                                    MainActivity.this.finish();                   //关闭MainActivity
                                }
                            })
                            //添加“取消”按钮
                            .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();                             //关闭对话框
                                }
                            });
                    dialog = builder.create();
                    dialog.show();
                }
            });
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

    github源码地址:

    https://github.com/xinyangwy/Android_QQ
    (含有build、release文件夹,约60多M)

  • 相关阅读:
    DSPE-PEG-FITC Fluorescein-PEG-DSPE 磷脂-聚乙二醇-荧光素
    中国范围逐月夜间灯光数据(2012-2021年)
    OpenCV每日函数 计算摄影模块(2) 图像去噪算法
    有 AI,无障碍,AIoT 设备为视障人群提供便利
    与堆和堆排序相关的问题
    python开发工程师面试准备
    nodejs开发的小程序 老年人健康预警系统
    双软认证办理流程,需要材料
    cmake简洁教程 - 第五篇
    白话讲解UML的4大关系:关联关系、泛化关系、依赖关系、实现关系
  • 原文地址:https://blog.csdn.net/weixin_45912291/article/details/125792927