FirebaseUI自定义布局不显示

时间:2019-07-23 03:25:49

标签: java android kotlin firebase-authentication firebaseui

我已经创建了用于身份验证的自定义布局,但是没有显示该布局,而是显示了电子邮件登录屏幕

val customLayout = AuthMethodPickerLayout.Builder(R.layout.custom_signinbasic)
                .setPhoneButtonId(R.id.buttonPhone)
                .setEmailButtonId(R.id.buttonEmail)
                .build()

            startActivityForResult(
                       AuthUI.getInstance().createSignInIntentBuilder()
                .setAuthMethodPickerLayout(customLayout)
                .build(),
            Signin_Request_Code)

布局

<androidx.constraintlayout.widget.ConstraintLayout 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">

    <Button
            android:text="Login with Email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/buttonEmail" android:layout_marginTop="8dp"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp" app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintVertical_bias="0.335"/>
    <Button
            android:text="Login with Phone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/buttonPhone" android:layout_marginTop="8dp"
            app:layout_constraintTop_toBottomOf="@+id/buttonEmail" android:layout_marginBottom="8dp"
            app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
            android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
            app:layout_constraintHorizontal_bias="0.487" app:layout_constraintVertical_bias="0.067"/>

</androidx.constraintlayout.widget.ConstraintLayout>

显示内容

enter image description here

1 个答案:

答案 0 :(得分:0)

首先,您需要设置提供商列表:

List<IdpConfig> selectedProviders = new ArrayList<>();
            selectedProviders.add(new AuthUI.IdpConfig.EmailBuilder().build());
            selectedProviders.add(new AuthUI.IdpConfig.PhoneBuilder().build());

科特琳:

val selectedProviders = mutableListOf<AuthUI.IdpConfig>()
    providers.add(AuthUI.IdpConfig.EmailBuilder().build())
    providers.add(AuthUI.IdpConfig.PhoneBuilder().build())

然后创建SinginIntentBuilder:

            AuthUI.SignInIntentBuilder builder = AuthUI.getInstance().createSignInIntentBuilder();

按照已创建的方式创建自定义布局:

            AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
                    .Builder(R.layout.activity_login) //your layout name
                    .setPhoneButtonId(R.id.buttonPhone)
                    .setEmailButtonId(R.id.buttonEmail)
                    .build();

然后传递构建器和提供者并开始结果活动:

            startActivityForResult(builder.setAuthMethodPickerLayout(customLayout)
                    .setAvailableProviders(selectedProviders)//provider list
                    .setTheme(R.style.AppTheme)//app theme or whatever theme you want
                    .setIsSmartLockEnabled(false)
                    .build(),RC_SIGN_IN);