Android 注册登录界面实现示例代码
本文介绍如何在 Android 应用中实现基础的注册与登录界面。通过 Java 语言编写 Activity,结合 XML 布局文件构建用户界面,并演示页面跳转逻辑及资源管理方式。
项目配置
在 build.gradle 文件中配置编译版本和依赖项。本示例使用较旧的 Support 库以兼容旧版 SDK,实际开发建议迁移至 AndroidX。
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "online.geekgalaxy.layoutlearn"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
清单文件配置
在 AndroidManifest.xml 中声明应用包名、主题以及各个 Activity 的入口点。确保登录和注册页面被正确注册。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="online.geekgalaxy.layoutlearn">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">


