2018年Android平台社交媒体登录的便捷实现方案咨询
Hey there! Let's sort out your sign-in styling and deprecated code issues right away.
First off, you're totally correct that parts of AuthUI.getInstance().createSignInIntentBuilder() are deprecated, and Google Identity Toolkit is long retired (since 2013—definitely not something to use now). The good news is there's a modern, maintained solution that will fix your button styling consistency problem in one go: using Firebase AuthUI's updated IdpConfig builders.
Here's how to implement it:
1. Set Up Identity Provider Configs
Instead of the old, deprecated builder approach, you'll create individual configs for Google and Facebook using their dedicated builders. This keeps your provider settings clear while letting AuthUI handle uniform styling.
Java Code Snippet:
// Configure Google Sign-In IdpConfig googleConfig = new IdpConfig.GoogleBuilder() .build(); // Configure Facebook Sign-In IdpConfig facebookConfig = new IdpConfig.FacebookBuilder() .build(); // Combine providers into a list List<IdpConfig> signInProviders = Arrays.asList(googleConfig, facebookConfig);
Kotlin Code Snippet:
// Configure Google Sign-In val googleConfig = IdpConfig.GoogleBuilder().build() // Configure Facebook Sign-In val facebookConfig = IdpConfig.FacebookBuilder().build() // Combine providers into a list val signInProviders = listOf(googleConfig, facebookConfig)
2. Build the Updated Sign-In Intent
The createSignInIntentBuilder() method is still usable—only the old constants it relied on are deprecated. Now you'll pass your configured providers to it, and AuthUI will generate a unified sign-in screen with consistent button styles:
Java Code:
Intent signInIntent = AuthUI.getInstance() .createSignInIntentBuilder() .setAvailableProviders(signInProviders) .setTheme(R.style.YourAppAuthTheme) // Optional: match your app's theme .build(); startActivityForResult(signInIntent, YOUR_SIGN_IN_REQUEST_CODE); // Use your own request code
Kotlin Code:
val signInIntent = AuthUI.getInstance() .createSignInIntentBuilder() .setAvailableProviders(signInProviders) .setTheme(R.style.YourAppAuthTheme) // Optional: customize to fit your app .build() startActivityForResult(signInIntent, YOUR_SIGN_IN_REQUEST_CODE)
Why This Solves Your Styling Problem
By letting AuthUI handle the sign-in UI, all buttons (Google, Facebook, and any other providers you add) will automatically use matching styles that align with your app's theme. No more manually styling each button and dealing with inconsistencies!
Bonus: Customize the Theme (If Wanted)
If you want to tweak the look even more to match your app's design, create a custom theme extending your app's base theme (like Theme.MaterialComponents.Light.NoActionBar) and override attributes like:
colorPrimary: Sets the main button colorcolorAccent: Adjusts accent elementsauthButtonStyle: Lets you modify button padding, text size, and more
Just reference this custom theme in the setTheme() method when building your sign-in intent.
内容的提问来源于stack exchange,提问作者Marian Klühspies

