How can we use android: inputType in EditTextPreference?

I checked the documentation of EditTextPreference http://developer.android.com/reference/android/preference/EditTextPreference.html

But I could not find the android: inputType attribute there. Then how can this be used in this code segment

<EditTextPreference
        android:key="edit"
        android:title="@string/location1"
        android:summary="@string/summary1"
        android:dialogTitle="@string/location1"
        android:dialogMessage="@string/message"
        android:inputType="text"
        android:singleLine="true"
        />

The same doubt for the android: singleLine attribute.

+7
source share
4 answers

Documents do not list the attributes for this class, but the attribute InputType(and other attributes EditTextand TextView) still work. This is indicated only in the text. Also see this related question .

EditTextPreference , :

. EditText.

(, , , ), inputType . ( ):

  • textCapCharacters
  • textCapWords
  • textCapSentences
  • textAutoCorrect
  • textAutoComplete
  • textMultiLine
  • textImeMultiLine
  • textNoSuggestions
  • textUri
  • textEmailAddress
  • textEmailSubject
  • textShortMessage
  • textLongMessage
  • textPersonName
  • textPostalAddress
  • textPassword
  • textVisiblePassword
  • textWebEditText
  • TextFilter
  • textPhonetic
  • textWebEmailAddress
  • textWebPassword
  • numberSigned
  • numberDecimal
  • numberPassword

-, , | ( ).

+3

XML, EditTextpreference EditText, . Activity/Fragment :

EditTextPreference pref = (EditTextPreference) PreferenceManager.findPreference("edit");
EditText prefEditText = pref.getEditText();
prefEditText.setInputType(InputType.TYPE_CLASS_TEXT);
prefEditText.setSingleLine(true);
// etc
+1

androidX .

0

AndroidX, , :

root_preferences.xml:

<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <Preference
        android:title="Password"
        android:key="my_pref_password"/>
</androidx.preference.PreferenceScreen>

:

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.root_preferences, rootKey);


    EditTextPreference pref = findPreference("my_pref_password");
    pref.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
        @Override
        public void onBindEditText(@NonNull EditText editText) {
            editText.setInputType(InputType.TYPE_CLASS_TEXT |
                            InputType.TYPE_TEXT_VARIATION_PASSWORD);
        }
    });
}
0

All Articles