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

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



注:实验环境 Android studio 2021.2.1

1、头像设计

  • 首先在layout文件里面选择了RelativeLayout(相对布局)作为整个页面的布局。用下面的属性设置布局中子元素的排列方式为垂直排列;
android:orientation="vertical"
  • 在顶端放置了一个ImageView控件,id设为“iv”,宽度和高度设置的都是70dp。设置为水平居中;
android:layout_centerHorizontal="true"
  • 然后使头像在整个页面下调一点,不要紧贴着顶端,所以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

<?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: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" />
        <!--layout_weight="1" layout_width="0dp"实现均分效果-->
    </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>

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();
            }
        });
    }
}

github源码地址:

https://github.com/xinyangwy/Android_QQ

(含有build、release文件夹,约60多M)

相关文章
|
2月前
|
Java Android开发 C++
Android Studio JNI 使用模板:c/cpp源文件的集成编译,快速上手
本文提供了一个Android Studio中JNI使用的模板,包括创建C/C++源文件、编辑CMakeLists.txt、编写JNI接口代码、配置build.gradle以及编译生成.so库的详细步骤,以帮助开发者快速上手Android平台的JNI开发和编译过程。
91 1
|
11天前
|
XML Android开发 UED
💥Android UI设计新风尚!掌握Material Design精髓,让你的界面颜值爆表!🎨
随着移动应用市场的蓬勃发展,用户对界面设计的要求日益提高。为此,掌握由Google推出的Material Design设计语言成为提升应用颜值和用户体验的关键。本文将带你深入了解Material Design的核心原则,如真实感、统一性和创新性,并通过丰富的组件库及示例代码,助你轻松打造美观且一致的应用界面。无论是色彩搭配还是动画效果,Material Design都能为你的Android应用增添无限魅力。
27 1
|
22天前
|
XML IDE 开发工具
🔧Android Studio高级技巧大公开!效率翻倍,编码不再枯燥无味!🛠️
【9月更文挑战第11天】在软件开发领域,Android Studio凭借其强大的功能成为Android开发者的首选IDE。本文将揭示一些提升开发效率的高级技巧,包括自定义代码模板、重构工具、高级调试技巧及多模块架构。通过对比传统方法,这些技巧不仅能简化编码流程,还能显著提高生产力。例如,自定义模板可一键插入常用代码块;重构工具能智能分析并安全执行代码更改;高级调试技巧如条件断点有助于快速定位问题;多模块架构则提升了大型项目的可维护性和团队协作效率。掌握这些技巧,将使你的开发之旅更加高效与愉悦。
44 5
|
2月前
|
Dart Android开发
Android Studio New里面没有New Flutter Project
Android Studio New里面没有New Flutter Project
103 1
Android Studio New里面没有New Flutter Project
|
2月前
|
编解码 Android开发
【Android Studio】使用UI工具绘制,ConstraintLayout 限制性布局,快速上手
本文介绍了Android Studio中使用ConstraintLayout布局的方法,通过创建布局文件、设置控件约束等步骤,快速上手UI设计,并提供了一个TV Launcher界面布局的绘制示例。
37 1
|
2月前
|
Android开发
Android Studio: 解决Gradle sync failed 错误
本文介绍了解决Android Studio中出现的Gradle同步失败错误的步骤,包括从`gradle-wrapper.properties`文件中获取Gradle的下载链接,手动下载Gradle压缩包,并替换默认下载路径中的临时文件,然后重新触发Android Studio的"Try Again"来完成同步。
376 0
Android Studio: 解决Gradle sync failed 错误
|
2月前
|
Java Android开发 芯片
使用Android Studio导入Android源码:基于全志H713 AOSP,方便解决编译、编码问题
本文介绍了如何将基于全志H713芯片的AOSP Android源码导入Android Studio以解决编译和编码问题,通过操作步骤的详细说明,展示了在Android Studio中利用代码提示和补全功能快速定位并修复编译错误的方法。
48 0
使用Android Studio导入Android源码:基于全志H713 AOSP,方便解决编译、编码问题
|
2月前
|
API 开发工具 Android开发
Android Studio:解决AOSP自编译framework.jar引用不到的问题
在Android Studio中解决AOSP自编译framework.jar引用问题的几种方法,包括使用相对路径、绝对路径和通过`${project.rootDir}`动态获取路径的方法,以避免硬编码路径带来的配置问题。
43 0
Android Studio:解决AOSP自编译framework.jar引用不到的问题
|
2月前
|
Dart 开发工具 Android开发
Android Studio导入Flutter项目提示Dart SDK is not configured
Android Studio导入Flutter项目提示Dart SDK is not configured
92 4
|
2月前
|
Java 网络安全 开发工具
UNITY与安卓⭐一、Android Studio初始设置
UNITY与安卓⭐一、Android Studio初始设置
下一篇
无影云桌面