首页 > 解决方案 > 如何更改 Firebase UI (Android) 国家代码选择器中文本的颜色

问题描述

我在我的应用程序中使用 Firebase UI 4.0.1,它通过以下主题使用AuthUI.getInstance().createSignInIntentBuilder().setTheme(R.style.LoginTheme)

<style name="Base"  parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primaryColor</item>
    <item name="colorPrimaryDark">@color/primaryDarkColor</item>
    <item name="colorAccent">@color/secondaryColor</item>
    <item name="android:windowBackground">@color/primaryColor</item>
</style>

<style name="Base.AppTheme">
    <!-- Customize your theme here. -->
    <item name="android:editTextStyle">@style/Yas_EditTextStyle</item>
    <item name="editTextStyle">@style/Yas_EditTextStyle</item>
    <item name="android:textColor">@color/primaryTextColor</item>
</style>

<style name="AppTheme" parent="Base.AppTheme">
    <item name="android:windowTranslucentStatus">true</item>
</style>

<style name="LoginTheme" parent="@style/Base">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:alertDialogStyle">@style/Login_AlertDialogStyle</item>
</style>

<style name="Login_AlertDialogStyle" parent="@style/AlertDialog.AppCompat.Light">
    <item name="android:textColorAlertDialogListItem">@android:color/black</item>
    <item name="android:textColor">@android:color/black</item>
</style>

注意primaryTextColor是白色的。当我这样做时,一切看起来都很好,直到我打开国家代码选择器的警报对话框。在那里我得到一个国家列表,但文本是白色背景上的白色。我试图让该文本变为黑色,但它在白色上显示为白色。这是正在调用的对话框类的链接:https ://github.com/firebase/FirebaseUI-Android/blob/master/auth/src/main/java/com/firebase/ui/auth/ui/phone/CountryListSpinner .java#L163

如何确保 Firebase UI 使用我的Login_AlertDialogStyle?

标签: androidfirebaseui

解决方案


尝试将此添加到您的 FirebaseUI 主题:

<item name="android:alertDialogTheme">@style/Login_AlertDialogStyle</item>

您首先需要在您的 中创建一个自定义 FirebaseUI 主题styles.xml,该主题必须从 FirebaseUI 扩展。然后,您需要通过 AuthUI 构建器设置此样式:

样式.xml

<style name="SignInTheme" parent="FirebaseUI">
    <item name="android:alertDialogTheme">@style/Login_AlertDialogStyle</item>
    <!-- Feel free to add anything else you want here -->
</style>

活动类

Intent firebaseAuth = AuthUI.getInstance()
    .createSignInIntentBuilder()
    .setTheme(R.style.SignInTheme) // set your sign in theme here
    .setAvailableProviders(Arrays.asList(
        new AuthUI.IdpConfig.PhoneBuilder().build(),
        new AuthUI.IdpConfig.GoogleBuilder().build()))
    .build();

有关自定义 UI 的更多信息:https ://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#ui-customization


推荐阅读