How to show Android keyboard with symbols mode by default?

前端 未结 5 911
余生分开走
余生分开走 2020-12-06 01:55

I have a EditText component, and, of course, if you click on it, the Android keypad is shown, allowing the user to input text. As far as I know, all Android sof

5条回答
  •  悲哀的现实
    2020-12-06 02:20

    The only way to do this is by setting the inputType of your EditText.

    If you want to set this property in the onCreate() (or inside a custom View's constructor) you can use the method setRawInputType():

    mEditText.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    

    Otherwise, if you need to set this property after the onCreate() (or after a custom View's constructor), you can use the method setInputType():

    mEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    

    Obviously you can also specify the property at XML level:

    android:inputType="number|numberDecimal"
    

    You can play around with different flags to find the best composed filter.

提交回复
热议问题