Unable to hide the Title bar of Authorization Activity using FirebaseUI

情到浓时终转凉″ 提交于 2020-12-29 06:48:06

问题


I tried to use the following style

<style name= "AuthStyle">
<item name="android:windowBackground">@drawable/culture</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>

and then I applied the above style here:

startActivityForResult(AuthUI.getInstance()
                .createSignInIntentBuilder()
                .setProviders(AuthUI.EMAIL_PROVIDER,
                              AuthUI.FACEBOOK_PROVIDER,
                              AuthUI.GOOGLE_PROVIDER)
                .setTheme(R.style.AuthStyle)
                .build()
                ,1);

However,the title bar is still being displayed. Any suggestions on how to remove / hide it will be appreciated


回答1:


Firebase UI overrides/ignores the removal of the action bar/app bar in the theme, so we have to cheat. In styles.xml:

<style name="AppThemeFirebaseAuth" parent="android:Theme.Material.Light.NoActionBar">
    <item name="android:actionBarStyle">@style/FirebaseAuthActionBarStyle</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="FirebaseAuthActionBarStyle" parent="Widget.AppCompat.ActionBar">
    <item name="android:background">@color/white</item>
</style>

(or rather than @color/white, whatever your background colour.)

Where you start the activity for sign in:

    Intent signInIntent = AuthUI.getInstance().createSignInIntentBuilder()
            .setProviders(Arrays.asList(
                    new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
                    new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build()))
            .setTheme(R.style.AppThemeFirebaseAuth)
            .setLogo(R.drawable.logo)
            .setIsSmartLockEnabled(!BuildConfig.DEBUG)
            .build();

Keep in mind that in future releases of Firebase UI, the action bar/app bar might become useful or required, so this is a bit dangerous.




回答2:


As of firebase ui version 4.3.1, the following code is enough to hide tiltebar, no need to do tricks with background color:

<style name="AppThemeFirebaseAuth" parent="android:Theme.Light.NoTitleBar">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

just reference the style when creating AuthUI instance

// Choose authentication providers
List<AuthUI.IdpConfig> providers = Arrays.asList(
    new AuthUI.IdpConfig.PhoneBuilder().build());
AuthUI.createSignInIntentBuilder()
      .setAvailableProviders(providers)
      .setTheme(R.style.AppThemeFirebaseAuth)
      .build(),

Tested in android 4.4.2 and android 9 (Nexus emulators)



来源:https://stackoverflow.com/questions/39136738/unable-to-hide-the-title-bar-of-authorization-activity-using-firebaseui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!