【发布时间】:2021-07-13 02:02:25
【问题描述】:
我正在使用 Firebase 用户界面并使用此代码覆盖其主题。
val builder = AuthUI.getInstance().createSignInIntentBuilder()
.setTheme(R.style.AuthStyle)
.setLogo(R.mipmap.ic_launcher)
.setIsSmartLockEnabled(true)
.setAvailableProviders(getProviderList())
builder.setTosAndPrivacyPolicyUrls(
"https://firebase.google.com/terms/",
"https://firebase.google.com/policies/analytics"
)
很遗憾,在使用 深色模式 时,windowBackground 不适用,backgroundTint 和 materialThemeOverlay 也不适用于按钮。
这是我完整的theme.xml 代码
<style name="AuthStyle" parent="Theme.MaterialComponents.DayNight">
<!--Override action bar and status bar-->
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorControlNormal">@color/colorAccent</item> <!--Spinner or non focus field underline color-->
<item name="android:colorFocusedHighlight">@color/colorAccent</item>
<!--Override Toolbar title text when using MaterialComponent-->
<item name="toolbarStyle">@style/AppToolbar</item>
<item name="materialButtonStyle">@style/AuthButton</item> <!--Customize Firebase UI button when using MaterialComponent-->
<!--Override main background-->
<item name="android:windowBackground">@color/whitePrimaryDark</item>
<!--Description text color-->
<item name="android:textColorTertiary">@color/primaryDarkWhite</item>
<!-- <item name="android:textColorPrimary">@color/colorPrimary</item>-->
<!--Override resend code text color-->
<item name="android:textColorSecondary">?android:textColorTertiary</item> <!--This override spinner item text too when using MaterialComponent-->
</style>
<!--Extend MaterialComponent Button when using MaterialComponents as app main theme-->
<style name="AuthButton" parent="Widget.MaterialComponents.Button">
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/whitePrimaryDark</item>
<item name="materialThemeOverlay">@style/ThemeOverlay.App.Button</item>
</style>
<!--Override-->
<style name="ThemeOverlay.App.Button" parent="">
<item name="colorPrimary">@color/primaryDarkAccent</item>
</style>
这些颜色使用不同的十六进制代码,使用文件夹values 和values-night 分隔,其中包含两个colors.xml 文件。 Firebase UI(电话身份验证)在夜间模式下根本不尊重它。我还尝试使用与 themes.xml 相同的方法将 AuthStyle 光和夜分开,但效果不佳。
primaryDarkAccent //This color switch between (light) colorPrimaryDark and (night) colorAccent
whitePrimaryDark //This color switch between (light) @android:color/white and (night) colorPrimaryDark
primaryDarkWhite //This color switch between (light) colorPrimaryDark and (night) colorAccent @android:color/white
对于按钮着色,它只使用在AuthStyle 上定义的colorPrimary,而不是我定义的带有叠加层的颜色值,但这仅在浅色模式期间使用。黑暗/夜间模式似乎并没有真正遵循定义的颜色。
【问题讨论】:
-
我不确定,但 AuthUI 应该适用于 AppCompat 主题。尝试覆盖 ThemeOverlay.App.Button 中的 colorAccent
-
@GabrieleMariotti 没有任何变化,它似乎不承认我在
values-night文件夹下的颜色值,并且只使用values这是光而不是夜晚。 -
另外
windowBackground在黑暗模式下也使用普通的深色而不是我定义的颜色。 -
使用布局检查器检查按钮的类型。如果它是 AppCompatButton,则不会在应用主题中使用 materialButtonStyle
-
@GabrieleMariotti 谢谢我已经弄清楚出了什么问题
标签: android material-design firebaseui material-components-android