[英]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?
我只能叫一个Pogram键盘,但是如何使它只有数字呢?
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. 在所有示例中,它们通常使用带有inputType =“ number”的editText,但是我有一个空的活动,需要在其上用数字调用软键盘。
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
或在
xml
android:inputType = "numberPassword"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.