我们如何在EditTextPreference中使用android:inputType?

时间:2022-03-01 00:10:20

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

我检查了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

但我没有在那里找到android:inputType属性。然后如何在此代码段中使用它

<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.

同样怀疑android:singleLine属性。

2 个解决方案

#1


2  

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.

文档不列出该类的属性,但InputType属性(以及其他EditText和TextView属性)仍然有效。它只在文中说明。另请参阅此相关问题。

The EditTextPreference documentation doesn't explicitly list all the attributes it supports, but the text states:

EditTextPreference文档未明确列出它支持的所有属性,但文本指出:

See EditText Attributes.

请参见EditText属性。

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):

那里的链接不是很有用(它们可能重新组织了一些属性,但从未更新过它的某些链接),但这里是inputType值的直接链接。作为快速总结,这些值是(截至发布时):

  • none
  • text
  • textCapCharacters
  • textCapWords
  • textCapSentences
  • textAutoCorrect
  • textAutoComplete
  • textMultiLine
  • textImeMultiLine
  • textNoSuggestions
  • textUri
  • textEmailAddress
  • textEmailSubject
  • textShortMessage
  • textLongMessage
  • textPersonName
  • textPostalAddress
  • textPassword
  • textVisiblePassword
  • textWebEditText
  • textFilter
  • textPhonetic
  • textWebEmailAddress
  • textWebPassword
  • number
  • numberSigned
  • numberDecimal
  • numberPassword
  • phone
  • datetime
  • date
  • time

You can apparently use one or more of these, separated by a | (I've never done this though).

你可以显然使用其中一个或多个,用|分隔(我从来没有这样做过)。

#2


0  

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:

您无法从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


2  

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.

文档不列出该类的属性,但InputType属性(以及其他EditText和TextView属性)仍然有效。它只在文中说明。另请参阅此相关问题。

The EditTextPreference documentation doesn't explicitly list all the attributes it supports, but the text states:

EditTextPreference文档未明确列出它支持的所有属性,但文本指出:

See EditText Attributes.

请参见EditText属性。

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):

那里的链接不是很有用(它们可能重新组织了一些属性,但从未更新过它的某些链接),但这里是inputType值的直接链接。作为快速总结,这些值是(截至发布时):

  • none
  • text
  • textCapCharacters
  • textCapWords
  • textCapSentences
  • textAutoCorrect
  • textAutoComplete
  • textMultiLine
  • textImeMultiLine
  • textNoSuggestions
  • textUri
  • textEmailAddress
  • textEmailSubject
  • textShortMessage
  • textLongMessage
  • textPersonName
  • textPostalAddress
  • textPassword
  • textVisiblePassword
  • textWebEditText
  • textFilter
  • textPhonetic
  • textWebEmailAddress
  • textWebPassword
  • number
  • numberSigned
  • numberDecimal
  • numberPassword
  • phone
  • datetime
  • date
  • time

You can apparently use one or more of these, separated by a | (I've never done this though).

你可以显然使用其中一个或多个,用|分隔(我从来没有这样做过)。

#2


0  

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:

您无法从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