我创建了一种方法来解决这个错误(在三星 Galaxy S3、Acer A501 和 HTC Desire X 上测试):
// This method provides a work-around for a bug with EditTextPreference and the Samsung soft keyboard.
// When in landscape mode, the Samsung keyboard can obscure the text box, as it does not use fullscreen
// / extract mode like other keyboards do in this case. So we manually show an alert dialog with an
// EditText control, and update the preference value manually.
//
// Usage:
// Create a normal <Preference> in your XML file, then in your corresponding fragment, retrieve the
// preference object using its key and pass it to this method. E.g.
//
// EditTextPreferenceHelper.CreateEditTextPreferenceDialog(
// getActivity(),
// findPreference("yourPrefKey"));
public static void CreateEditTextPreferenceDialog(final Context context, Preference preference) {
preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(preference.getTitle());
final EditText textBox = new EditText(context);
textBox.setImeOptions(EditorInfo.IME_ACTION_DONE);
textBox.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT);
textBox.setText(PreferenceManager.getDefaultSharedPreferences(context).getString(preference.getKey(), ""));
builder.setView(textBox);
builder.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PreferenceManager.getDefaultSharedPreferences(
context).edit().putString(preference.getKey(),
textBox.getText().toString()).commit();
dialog.dismiss();
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
return false;
}
});
}