问题
I am showing the AccountPicker dialog from Google Play Services with this code:
String[] accountTypes = new String[]{"com.google"};
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
accountTypes, false, null, null, null, null);
startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
It appears as a dark themed dialog even though I am using AppCompat v21 with Theme.AppCompat.Light.
Is it possible to style the dialog? Preferably as a Material dialog on Lollipop but at least make it a light dialog to match my app.
回答1:
I think, no need to "hack". It can be achieved easier:
...
String[] accountTypes = new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE};
Intent intent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, false, description, null, null, null);
// set the style
if ( isItDarkTheme ) {
intent.putExtra("overrideTheme", 0);
} else {
intent.putExtra("overrideTheme", 1);
}
intent.putExtra("overrideCustomTheme", 0);
try {
startActivityForResult(intent, YOUR_REQUEST_CODE_PICK_ACCOUNT);
} catch (ActivityNotFoundException e) {
...
}
...
回答2:
I had the same problem, but I finally found the solution. Take a look to AccountPicker.class, where are methods: newChooseAccountIntent() and zza();
You have to change
AccountPicker.newChooseAccountIntent(null, null,
accountTypes, false, null, null, null, null);
to
AccountPicker.zza(null, null,
accountTypes, false, null, null, null, null, false, 1, 0);
Last two arguments are for "overrideTheme" and "overrideCustomTheme". So set the first one to 1 and it will override the theme to light. :-)
Hope it helps.
回答3:
My solution is
Intent intent = AccountPicker.a(null, null,accountTypes, true, null, null, null, null, false, 1, 0);
来源:https://stackoverflow.com/questions/28237798/change-style-of-google-play-services-accountpicker-dialog