Mun0n
Mun0n

Reputation: 4437

EditTextPreference single line

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

Answers (4)

lumag
lumag

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

CommonsWare
CommonsWare

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

Killyox
Killyox

Reputation: 99

Maybe android:singleLine="true" in the layout :

restrict edittext to single line

Upvotes: 8

Andrii Chernenko
Andrii Chernenko

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

Related Questions