
1. 创建新项目
- 打开Android Studio,选择“Start a new Android Studio project”。
- 选择一个合适的模板,例如“Empty Activity”,并设置项目名称、包名等。
- 点击“Finish”完成创建。
2. 设计登录界面
-
布局文件: 打开activity_main.xml文件,使用XML布局语言设计登录界面。
-
控件: 添加必要的控件,如EditText(用于输入用户名和密码)、Button(用于提交登录信息)、TextView(用于显示提示信息)。
-
约束布局: 使用ConstraintLayout来灵活地布局控件,确保在不同屏幕尺寸上显示效果良好。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.***/apk/res/android"
xmlns:app="http://schemas.android.***/apk/res-auto"
android:layout_width="match_parent"
android.layout_height="match_parent">
<EditText
android:id="@+id/etUsername