GenAuth DocsDocuments
Concepts
User Guide
Development Integration
AgentAuth
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Concepts
User Guide
Development Integration
AgentAuth
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Old version
  • Single Page Web Application

  • Mobile and Client Applications

    • Android

      • Quick Start
      • Hosted Pages
      • Components

        • Tutorial

          • 入门示例
          • 基础登录示例
          • 复杂登录示例
          • 完善登录界面
          • 基础注册示例
          • 复杂注册示例
          • 登录注册转场
          • 手机号码重置密码
          • 邮箱地址重置密码
          • 动态重置密码
        • Basic Components

        • Social Components

      • APIs

      • Social Login

      • Typical Scenarios

      • Private Deployment
      • Version History
    • C#

    • Flutter

    • iOS

    • React Native
  • Standard Web Application

  • Framework Integration

  • Others

  1. Development Integration
  2. /
  3. Mobile and Client Applications
  4. /
  5. Android
  6. /
  7. Components
  8. /
  9. Tutorial

  10. /
  11. 复杂登录示例

¶ 复杂登录示例

Update time: 2025-07-23 07:34:21
Edit

阅读此教程之前,确保已经完成了 开发准备

在上一个 基础登录教程 里面,我们构建了一个简单的登录界面,接下来我们尝试构建一个更为复杂的登录界面,它包含一个可以切换登录方式的 Tab,支持帐号+密码登录以及电话号码+验证码登录

¶ 放置 LoginMethodTab

放置一个 LoginMethodTab

LoginMethodTab 可以用来切换登录方式,它可以根据控制台设置动态调整显示类容,更多信息请参考 详细说明

¶ 放置手机号+验证码登录相关组件

放置 PhoneNumberEditText、VerifyCodeEditText、GetVerifyCodeButton

更多 GetVerifyCodeButton 属性设置,请参考 详细说明

运行看看效果:

drawing

现在可以通过手机号+验证码成功登录!因为 Guard 内部的实现优先选择手机号+验证码的方式。

¶ 放置邮箱+验证码登录相关组件

放置 EmailEditText、VerifyCodeEditText、GetEmailCodeButton

更多 GetEmailCodeButton 属性设置,请参考 详细说明

运行看看效果:

drawing

到目前为止,我们只是简单地将所有控件都放置到了界面上。接下来,我们需要将组件分组,从而实现切换效果。

¶ 放置 LoginContainer 并将组件添加到容器里面

放置一个 LoginContainer,将 AccountEditText 和 PasswordEditText 放到第一个 LoginContainer 里,设置 type 属性app:type="accountPassword"。

再放置一个 LoginContainer,将 PhoneNumberEditText、VerifyCodeEditText、GetVerifyCodeButton 放到第二个 LoginContainer 里面,设置 type 属性,app:type="phoneCode"。

再放置一个 LoginContainer,将 EmailEditText、VerifyCodeEditText、GetEmailCodeButton 放到第三个 LoginContainer 里面,设置 type 属性,app:type="emailCode"。

¶ 完成

drawing drawing drawing

¶ 完整示例代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <cn.authing.guard.AppLogo
        android:id="@+id/app_logo"
        android:layout_width="68dp"
        android:layout_height="68dp"
        android:layout_marginTop="40dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/app_name"
        app:layout_constraintVertical_chainStyle="packed"
        android:src="@drawable/ic_authing_default_logo"/>

    <cn.authing.guard.AppName
        android:id="@+id/app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="移动 Guard 示例"
        android:layout_marginTop="20dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/app_logo"
        app:layout_constraintBottom_toTopOf="@+id/login_method_tab"
        app:layout_constraintEnd_toEndOf="parent"/>

    <cn.authing.guard.LoginMethodTab
        android:id="@+id/login_method_tab"
        android:layout_width="match_parent"
        android:layout_height="52dp"
        android:layout_marginTop="32dp"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/app_name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/account_login"/>

    <cn.authing.guard.LoginContainer
        android:id="@+id/account_login"
        app:type="accountPassword"
        android:clipChildren="false"
        android:visibility="invisible"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginTop="16dp"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/login_method_tab"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/phone_code_login">
        <cn.authing.guard.AccountEditText
            android:id="@+id/account"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            app:leftIconDrawable="@drawable/ic_authing_user"
            app:errorEnabled="true" />
        <cn.authing.guard.PasswordEditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:layout_marginTop="0dp"
            app:leftIconDrawable="@drawable/ic_authing_password"
            app:clearAllEnabled="false"
            app:errorEnabled="false" />
    </cn.authing.guard.LoginContainer>

    <cn.authing.guard.LoginContainer
        android:id="@+id/phone_code_login"
        app:type="phoneCode"
        android:clipChildren="false"
        android:visibility="invisible"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginTop="16dp"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/account_login"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/email_code_login">
        <cn.authing.guard.PhoneNumberEditText
            android:id="@+id/phone_number"
            android:background="@null"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:errorEnabled="true"
            app:leftIconDrawable="@drawable/ic_authing_cellphone">
        </cn.authing.guard.PhoneNumberEditText>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <cn.authing.guard.VerifyCodeEditText
                android:id="@+id/phone_verify_code"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@null"
                app:errorEnabled="false"
                app:leftIconDrawable="@drawable/ic_authing_shield_check" />
            <cn.authing.guard.GetVerifyCodeButton
                android:id="@+id/get_phone_verify_code"
                android:stateListAnimator="@null"
                android:background="@drawable/authing_get_code_button_background"
                android:layout_width="wrap_content"
                android:layout_height="42dp"
                android:layout_marginStart="4dp"
                android:paddingStart="4dp"
                android:paddingEnd="4dp"
                android:textColor="@color/button_text" />
        </LinearLayout>
    </cn.authing.guard.LoginContainer>

    <cn.authing.guard.LoginContainer
        android:id="@+id/email_code_login"
        app:type="emailCode"
        android:clipChildren="false"
        android:visibility="invisible"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginTop="16dp"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/phone_code_login"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/error_tip">
        <cn.authing.guard.EmailEditText
            android:id="@+id/email"
            android:background="@null"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:errorEnabled="true"
            app:leftIconDrawable="@drawable/ic_authing_email"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <cn.authing.guard.VerifyCodeEditText
                android:id="@+id/email_verify_code"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@null"
                app:errorEnabled="false"
                app:leftIconDrawable="@drawable/ic_authing_shield_check"/>
            <cn.authing.guard.GetEmailCodeButton
                android:id="@+id/get_email_verify_code"
                android:stateListAnimator="@null"
                android:background="@drawable/authing_get_code_button_background"
                android:layout_width="wrap_content"
                android:layout_height="42dp"
                android:layout_marginStart="4dp"
                android:paddingStart="4dp"
                android:paddingEnd="4dp"
                android:textColor="@color/button_text"/>
        </LinearLayout>
    </cn.authing.guard.LoginContainer>

    <cn.authing.guard.ErrorTextView
        android:id="@+id/error_tip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginTop="8dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/email_code_login"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/login_button"/>

    <cn.authing.guard.LoginButton
        android:id="@+id/login_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp"
        android:layout_marginTop="24dp"
        android:textStyle="bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/error_tip"                     
        app:layout_constraintEnd_toEndOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Previous article: 基础登录示例 Next article: 完善登录界面
  • 放置 LoginMethodTab
  • 放置手机号+验证码登录相关组件
  • 放置邮箱+验证码登录相关组件
  • 放置 LoginContainer 并将组件添加到容器里面
  • 完成
  • 完整示例代码

User identity management

Integrated third-party login
Customized authentication process

Enterprise internal management

Single sign-on
Multi-factor authentication
Permission management

Developer

Development Documentation
GitHub (opens new window)

Company

official@genauth.ai
16th Floor, Building B, Beichen Century Center, Chaoyang District, Beijing (Total)
Room 406, 4th Floor, Block B, No. 200, Tianfu Fifth Street, High-tech Zone, Chengdu (Branch)

© Beijing Steamory Technology Co., Ltd.