Change style of Google Play Services AccountPicker dialog

不羁的心 提交于 2019-12-05 17:30:51

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

    ...

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.

My solution is

Intent intent = AccountPicker.a(null, null,accountTypes, true, null, null, null, null, false, 1, 0); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!