Reputation: 4437
Is there anyway to make an EditTextPreference single line? I think that there is no property by default, that can do that. Is necessary to rewrite the object? Anyone have this done?
Upvotes: 3
Views: 2954
Reputation: 61
The following code works now with androidx.preferences >= 1.1.0-alpha01
:
EditTextPreference author_name_pref = findPreference(getString(R.string.author_name_key));
if (author_name_pref != null) {
author_name_pref.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
@Override
public void onBindEditText(@NonNull EditText editText) {
editText.setSingleLine();
}
});
}
Upvotes: 6
Reputation: 1006664
<EditTextPreference>
supports the attributes available for <EditText>
, and so you should be able to use android:inputMode
and such to control the behavior of the EditText
widget.
Upvotes: 1
Reputation: 99
Maybe android:singleLine="true"
in the layout :
restrict edittext to single line
Upvotes: 8
Reputation: 10194
You can obtain EditText
which backs up your EditTextPreference
by calling getEditText()
. And then do whatever you like with it, like with regular EditText
:
EditTextPreference pref=new EditTextPreference(context);
EditText editText=pref.getEditText();
editText.setSingleLine(true);
Upvotes: 2