How do I set multiple input types in an EditText on Android?

后端 未结 3 1543
说谎
说谎 2021-02-07 09:45

I am trying to create an EditText with auto-capitalization and auto-correction implemented. I have manually figured out how to add InputFilters to allo

相关标签:
3条回答
  • 2021-02-07 09:46

    Through XML it would be setup like so.

    android:inputType="textMultiLine|textNoSuggestions"
    

    You simply add a pipe (|) between variables. I see you were doing it through code but I was just throwing this out there for reference.

    0 讨论(0)
  • 2021-02-07 09:56

    yes, it seems like that should work. however, looking at the docs,

    The type of data being placed in a text field, used to help an input method decide how to let the user enter text. The constants here correspond to those defined by InputType. Generally you can select a single value, though some can be combined together as indicated. Setting this attribute to anything besides none also implies that the text is editable.

    http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType

    so it looks like in general, you can't expect to set two values. The above link shows which flags can be combined together.

    also, if you look at android:setInputType, it says this maps to the setRawInputType() method, not setInputType(). you might try calling setRawInputType() in stead of setInputType().

    http://developer.android.com/reference/android/widget/TextView.html#setRawInputType(int)

    0 讨论(0)
  • 2021-02-07 10:05

    I hope you've found an answer to the question. The answer might help those those come to the thread later. So, you can set multiple tags in similar manner as you do in XML using a | (pipe). Something like:

    EditText mEditText = new EditText(this);
    mEditText.setInputType(InputTpe.TYPE_TEXT_FLAG_CAP_CHARACTERS|InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    

    Also, depending on your situation you might want to use setInputTypeor setRawInputype.

    0 讨论(0)
提交回复
热议问题