我想显示系统对话框,用户可以从中选择他的谷歌帐户,并且我希望它在用户单击 EditTextPreference 时显示。问题是“正常”对话框一直显示在系统默认对话框之前。
这是代码。
public static class SettingsFragment extends PreferenceFragment {
Preference googleMail;
Intent intent = AccountPicker.newChooseAccountIntent(null, null,
new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE},
true, null, null, null, null);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
PreferenceCategory fakeHeader;
// Add 'fake' preferences.
addPreferencesFromResource(R.xml.pref_fake);
fakeHeader = new PreferenceCategory(getActivity().getBaseContext());
fakeHeader.setTitle(R.string.pref_header_calendar);
getPreferenceScreen().addPreference(fakeHeader);
addPreferencesFromResource(R.xml.pref_calendar);
bindPreferenceSummaryToValue(findPreference("pref_googleMail"));
googleMail = findPreference("pref_googleMail");
googleMail.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
startActivityForResult(intent, ACCOUNT_PICKED);
return false;
}
});
}
}