I'm trying to make a preference screen with AndroidX, but I'm encountering a small problem...
When I validate my entry with the "OK" button on the virtual keyboard, the preference is not validated. (keyboard is hidden, that's all...)
With AndroidX, we can no longer override showDialog()
in EditTextPreference
... and I couldn't find another way to access the dialog box to dismiss it.
In conclusion, what I wish: the DONE action of the button on the virtual keyboard validates the AlertDialog.
Here's my sample code:
XML file
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
app:key="pref_1"
app:title="Test"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>
Preference activity
public class MySettingsActivity extends AppCompatActivity implements
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
[...]
public static class HeaderFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.header_preferences, rootKey);
EditTextPreference pref1 = getPreferenceManager().findPreference("pref_1");
pref1.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
@Override
public void onBindEditText(@NonNull EditText editText) {
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
});
}
}
}