Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change style of Google Play Services AccountPicker dialog

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.

like image 293
Intrications Avatar asked Dec 25 '22 23:12

Intrications


2 Answers

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) {
        ...
    }

    ...
like image 195
braintrapp Avatar answered Jan 13 '23 12:01

braintrapp


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.

like image 20
Vojtech Pohl Avatar answered Jan 13 '23 12:01

Vojtech Pohl