Android : AccountPicker set Light Theme
M

2

8

Is it possible to set the theme of picker dialog ?

import com.google.android.gms.common.AccountPicker;
....
String[] accountTypes = new String[]{"com.google"};
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
                accountTypes, false, null, null, null, null);
activity.startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);

My base app theme is android:Theme.Light but that dialog is dark. Thanks.

Mastiff answered 26/2, 2014 at 16:51 Comment(1)
@Dayan Not a duplicate. Here poster is asking about changing theme on dialog we don't have control over (we didn't create it). The poster in the question you linked to is asking about changing theme on a dialog he/she created.Meir
S
9

If you wish to change the theme of the dialog, you should change the newChooseAccountIntent to zza and add two integer arguments. The first one is for overriding the theme and setting it to 1 will change the dialog theme to light.

String[] accountTypes = new String[]{"com.google"};
Intent intent = AccountPicker.zza(null, null, accountTypes, false, null, null, null, null, false, 1, 0);
startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT);
Shinny answered 21/8, 2015 at 11:39 Comment(5)
I am curious what are other theme are possible here?Campball
I couldn't find any documentation or code that would answer this question. You can experiment with it a little and let us know if you find out anything more about it :)Shinny
FYI, it seems like this is an internal/private API... so using this could break in the future.Leastwise
From GMS 16.x.x this method is gone. But still, you can use val intent = AccountPicker.newChooseAccountIntent and after: intent.putExtra("overrideTheme", 1) and it works :)Memo
why the 'zza' method?Metalware
E
3

you can change it when you overwrite over any args are defined in a parent class in method newChooseAccountIntent(Account var0, ArrayList<Account> var1, String[] var2, boolean var3, String var4, String var5, String[] var6, Bundle var7) {}

it is very simple to change it by adding it to your code...

Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, false, null, null, null, null). putExtra("overrideTheme", 1); startActivityForResult(intent, REQUEST_CODE_EMAIL);

1 means the Light Theme

0 means the Dark Theme

Elconin answered 28/4, 2018 at 15:31 Comment(1)
its is not working on android 10 google pixel 2 can you tell me why?Jadotville

© 2022 - 2024 — McMap. All rights reserved.