当前位置:   article > 正文

Android Studio欢迎界面和登陆界面的设计(小白)

android studio欢迎界面

        最近学校开设了Android Studio的开发课程,跟着书上的例子和小破站的视频开启了安卓小白之旅,今天主要整理了一下"欢迎界面"和"登陆界面"的相关内容。

        首先新建一个项目,按照自己的需求命名项目

 欢迎界面

新建一个类,命名为Splash

 欢迎界面的页面布局

在layout中新建一个activity_splash.xml文件,

需要首先在drawable文件夹下导入main_button_3图片,字体颜色可以自己按照喜好设计

activity_splash.xml布局设计如下

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:orientation="vertical"
  5. android:gravity="center"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent">
  8. <LinearLayout
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:orientation="vertical"
  12. android:background="@drawable/main_button_3"
  13. >
  14. <TextView
  15. android:id="@+id/textView"
  16. android:layout_marginTop="20dp"
  17. android:layout_marginLeft="80dp"
  18. android:layout_width="210dp"
  19. android:layout_height="wrap_content"
  20. android:text="我们的征途是星辰大海"
  21. android:textColor="@color/royalblue"
  22. android:textSize="40sp"
  23. android:textStyle="bold" />
  24. </LinearLayout>
  25. </LinearLayout>

效果如图

 Splash.java中代码如下:

  1. package com.example.chwngyanan.qxapp.activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.support.annotation.Nullable;
  5. import android.support.v7.app.AppCompatActivity;
  6. import com.example.chwngyanan.qxapp.MainActivity;
  7. import com.example.chwngyanan.qxapp.R;
  8. import java.util.Timer;
  9. import java.util.TimerTask;
  10. /**
  11. * Created by CHWNGYANAN on 2021/9/20.
  12. */
  13. public class Splash extends AppCompatActivity{
  14. @Override
  15. protected void onCreate(@Nullable Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.activity_splash); //快捷键alt+enter
  18. //延时操作
  19. Timer timer = new Timer();
  20. timer.schedule(timetast, 2000);
  21. }
  22. TimerTask timetast = new TimerTask() {
  23. @Override
  24. public void run() {
  25. startActivity(new Intent(Splash.this,Login.class));//跳转登录界面
  26. }
  27. };
  28. }

 Splash中要实现的功能是在欢迎界面停留两秒后跳转登陆界面

登陆界面

由于作者是小白,设计的登陆界面比较简单

新建Login类以及activity_login.xml

activity_login.xml布局文件如下

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".MainActivity">
  8. <LinearLayout
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:orientation="vertical"
  12. android:background="@drawable/main_button_3_selected"
  13. android:gravity="center">
  14. <LinearLayout
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"
  17. android:paddingBottom="30dp"
  18. android:paddingTop="20dp"
  19. android:background="#99404348"
  20. android:gravity="center">
  21. <TextView
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:layout_gravity="center"
  25. android:text="Welcome"
  26. android:textColor="#FFFFFF"
  27. android:textSize="18sp"/>
  28. </LinearLayout>
  29. <LinearLayout
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content"
  32. android:orientation="vertical"
  33. android:paddingBottom="20dp"
  34. android:paddingTop="20dp"
  35. android:background="#99000000">
  36. <EditText
  37. android:layout_width="match_parent"
  38. android:layout_height="wrap_content"
  39. android:background="@null"
  40. android:layout_gravity="center"
  41. android:layout_marginRight="50dp"
  42. android:layout_marginLeft="50dp"
  43. android:textColor="#9F9FA0"
  44. android:textColorHint="#9F9FA0"
  45. android:hint="your username"/>
  46. <View
  47. android:layout_width="match_parent"
  48. android:layout_height="1dip"
  49. android:background="#83738F"
  50. android:layout_marginRight="40dp"
  51. android:layout_marginLeft="40dp"
  52. android:layout_marginTop="10dp"
  53. android:layout_marginBottom="5dp"></View>
  54. <EditText
  55. android:layout_width="match_parent"
  56. android:layout_height="wrap_content"
  57. android:background="@null"
  58. android:layout_gravity="center"
  59. android:hint="your password"
  60. android:textColor="#9F9FA0"
  61. android:textColorHint="#9F9FA0"
  62. android:layout_marginLeft="50dp"
  63. android:layout_marginRight="50dp"/>
  64. </LinearLayout>
  65. <LinearLayout
  66. android:layout_width="match_parent"
  67. android:layout_height="wrap_content"
  68. android:paddingBottom="30dp"
  69. android:paddingTop="20dp"
  70. android:background="#99404348"
  71. android:gravity="center"
  72. android:orientation="horizontal">
  73. <TextView
  74. android:layout_width="wrap_content"
  75. android:layout_height="wrap_content"
  76. android:layout_gravity="center"
  77. android:text="Forget Password?"
  78. android:textColor="#DDDDDD"
  79. android:textSize="15sp"/>
  80. <TextView
  81. android:layout_width="wrap_content"
  82. android:layout_height="wrap_content"
  83. android:layout_gravity="center"
  84. android:text="Tap Here"
  85. android:textColor="#FFFFFF"
  86. android:textSize="15sp"/>
  87. </LinearLayout>
  88. <LinearLayout
  89. android:layout_width="match_parent"
  90. android:layout_height="wrap_content"
  91. android:orientation="horizontal">
  92. <Button
  93. android:id="@+id/login"
  94. android:layout_width="wrap_content"
  95. android:layout_height="wrap_content"
  96. android:layout_marginLeft="40dp"
  97. android:layout_marginRight="10dp"
  98. android:layout_weight="1"
  99. android:background="@color/royalblue"
  100. android:text="Login"/>
  101. <Button
  102. android:id="@+id/zhuce"
  103. android:layout_width="wrap_content"
  104. android:layout_height="wrap_content"
  105. android:layout_marginRight="40dp"
  106. android:layout_marginLeft="10dp"
  107. android:background="@color/royalblue"
  108. android:layout_weight="1"
  109. android:text="Sign in"/>
  110. </LinearLayout>
  111. </LinearLayout>
  112. </LinearLayout>

效果如图:

同样需要注意在drawable中导入名为main_button_3_selected的图片(图片名称可以自己命名,和xml文件中对应即可)

接下来要实现的功能是点击登录注册跳转注册界面

新建Register类以及activity_register.xml文件

activity_register.xml布局文件如下

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:orientation="vertical"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent">
  8. <LinearLayout
  9. android:layout_margin="10dp"
  10. android:orientation="vertical"
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content">
  13. <LinearLayout
  14. android:layout_marginTop="20dp"
  15. android:gravity="center"
  16. android:orientation="horizontal"
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content">
  19. tools:ignore="UselessParent">
  20. <TextView
  21. android:textStyle="bold"
  22. android:textSize="24sp"
  23. android:text="@string/数字账号"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content" />
  26. <EditText
  27. android:layout_width="match_parent"
  28. android:layout_height="wrap_content"
  29. android:hint="@string/输入账号"/>
  30. </LinearLayout>
  31. <LinearLayout
  32. android:layout_marginTop="20dp"
  33. android:gravity="center"
  34. android:orientation="horizontal"
  35. android:layout_width="match_parent"
  36. android:layout_height="wrap_content">
  37. tools:ignore="UselessParent">
  38. <TextView
  39. android:textStyle="bold"
  40. android:textSize="24sp"
  41. android:text="@string/数字密码"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content" />
  44. <EditText
  45. android:layout_width="match_parent"
  46. android:layout_height="wrap_content"
  47. android:hint="@string/请输入您的密码"/>
  48. </LinearLayout>
  49. <LinearLayout
  50. android:layout_marginTop="20dp"
  51. android:gravity="center"
  52. android:orientation="horizontal"
  53. android:layout_width="match_parent"
  54. android:layout_height="wrap_content">
  55. <TextView
  56. android:textStyle="bold"
  57. android:textSize="24sp"
  58. android:text="@string/具体昵称"
  59. android:layout_width="wrap_content"
  60. android:layout_height="wrap_content" />
  61. <EditText
  62. android:layout_width="match_parent"
  63. android:layout_height="wrap_content"
  64. android:hint="@string/请输入您的昵称"/>
  65. </LinearLayout>
  66. </LinearLayout>
  67. <Button
  68. android:id="@+id/register"
  69. android:layout_margin="10dp"
  70. android:background="@color/colorPrimaryDark"
  71. android:textSize="20sp"
  72. android:layout_width="match_parent"
  73. android:layout_height="wrap_content"
  74. android:text="@string/注册账号"/>
  75. </LinearLayout>

设计效果如图

 Register.java文件代码如下:

 实现的功能是当点击"注册账号"按钮时,跳转登录界面,并且显示“注册成功,请重新登录”字样

  1. package com.example.chwngyanan.qxapp.activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.support.annotation.Nullable;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.Toast;
  9. import com.example.chwngyanan.qxapp.MainActivity;
  10. import com.example.chwngyanan.qxapp.R;
  11. /**
  12. * Created by CHWNGYANAN on 2021/9/23.
  13. */
  14. public class Register extends AppCompatActivity {
  15. private Button register;
  16. @Override
  17. protected void onCreate(@Nullable Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.activity_register);
  20. //绑定按钮
  21. register = (Button)findViewById(R.id.register);
  22. register.setOnClickListener(new View.OnClickListener() {
  23. @Override
  24. public void onClick(View v) {
  25. Toast.makeText(Register.this, "注册成功,请重新登录", Toast.LENGTH_SHORT).show();
  26. startActivity(new Intent(Register.this,Login.class));
  27. }
  28. });
  29. }
  30. }

Login.java要实现的功能是 :点击登录,跳转主界面,并显示“登录成功”字样

Login.java中代码如下

  1. package com.example.chwngyanan.qxapp.activity;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.support.annotation.Nullable;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.widget.Toast;
  10. import com.example.chwngyanan.qxapp.MainActivity;
  11. import com.example.chwngyanan.qxapp.R;
  12. /**
  13. * Created by CHWNGYANAN on 2021/9/22.
  14. */
  15. public class Login extends AppCompatActivity {
  16. private Button login;
  17. private Button zhuce;
  18. @Override
  19. protected void onCreate(@Nullable Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_login);
  22. //绑定控件
  23. login = (Button)findViewById(R.id.login);
  24. zhuce = (Button)findViewById(R.id.zhuce);
  25. login.setOnClickListener(new View.OnClickListener() {
  26. @Override
  27. public void onClick(View v) {
  28. Toast.makeText(Login.this, "登陆成功",Toast.LENGTH_SHORT).show();
  29. startActivity(new Intent(Login.this, MainActivity.class));
  30. }
  31. });
  32. //注册界面
  33. zhuce.setOnClickListener(new View.OnClickListener() {
  34. @Override
  35. public void onClick(View v) {
  36. startActivity(new Intent(Login.this,Register.class));
  37. }
  38. });
  39. }
  40. }

最后实现的效果如下:

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/765126
推荐阅读
相关标签
  

闽ICP备14008679号