问题
I have created a custom layout for authentication, but the layout is not shown and Email login screen is displayed instead
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)
Layout
<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>
What is displays
回答1:
First you need to set Provider list:
List<IdpConfig> selectedProviders = new ArrayList<>();
selectedProviders.add(new AuthUI.IdpConfig.EmailBuilder().build());
selectedProviders.add(new AuthUI.IdpConfig.PhoneBuilder().build());
Kotlin:
val selectedProviders = mutableListOf<AuthUI.IdpConfig>()
providers.add(AuthUI.IdpConfig.EmailBuilder().build())
providers.add(AuthUI.IdpConfig.PhoneBuilder().build())
then create SinginIntentBuilder:
AuthUI.SignInIntentBuilder builder = AuthUI.getInstance().createSignInIntentBuilder();
Create custom layout as you have already created:
AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
.Builder(R.layout.activity_login) //your layout name
.setPhoneButtonId(R.id.buttonPhone)
.setEmailButtonId(R.id.buttonEmail)
.build();
then pass builder and provider and start activity for result:
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);
来源:https://stackoverflow.com/questions/57156257/firebaseui-custom-layout-doesnt-show