I checked the documentation of EditTextPreference http://developer.android.com/reference/android/preference/EditTextPreference.html
But I failed to found the android:inputType attribute there. Then how it can 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"
/>
Same doubt for the android:singleLine attribute.
The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.
A EditText is an overlay over TextView that configures itself to be editable. It is the predefined subclass of TextView that includes rich editing capabilities.
Setting the InputType of an EditText tells the system keyboard what kind of input you are expecting. If your edit text is for inputting a phone number, then you want the keyboard to show numbers.
The docs don't list the attributes for that class, but the InputType
attribute (and other EditText
and TextView
attributes) still work. It's only stated in the text. Also see this related question.
The EditTextPreference
documentation doesn't explicitly list all the attributes it supports, but the text states:
See EditText Attributes.
The link there isn't very useful (they probably reorganised some of the attributes but never updated some links to it), but here's a direct link to inputType values. As a quick summary those values are (as of the time of posting):
You can apparently use one or more of these, separated by a |
(I've never done this though).
You can't do it from XML, but EditTextpreference exposes the EditText so you can do it programmatically. After you load the preferences in your Activity/Fragment, you can do:
EditTextPreference pref = (EditTextPreference) PreferenceManager.findPreference("edit");
EditText prefEditText = pref.getEditText();
prefEditText.setInputType(InputType.TYPE_CLASS_TEXT);
prefEditText.setSingleLine(true);
// etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With