简体   繁体   中英

Numeric Soft Keyboard on Android on empty Activity

I want to call a soft keyboard with numbers, but I don't understand how to do this. I can call just a pogram keyboard, but how can I make it so that there are only numbers?

in all examples they usually use editText with inputType="number", but I have an empty activity on which I need to call the soft keyboard with numbers.

The simple answer is, you can't without setting an input type.

You can display the keyboard any time you like by calling:

InputMethodManager imm = (InputMethodManager)   getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

But in order to set it to set the keyboard to numeric, you need to set the input type, as shown below:

myEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);

or in xml

android:inputType = "numberPassword"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM