[英]Android EditText InputType, numeric keyboard + append text
I have this EditText where the user enter a credit card number. 我有这个EditText,用户可以在其中输入信用卡号。 I add a blank space every 4 characters by appending to the EditText like so: 我通过添加到EditText来每隔4个字符添加一个空格,如下所示:
cardNumberEditText.append(" ");
I only want to show the numeric keyboard. 我只想显示数字键盘。 Therefore I add this attribute to my EditText in XML: 因此,我将此属性添加到XML的EditText中:
android:inputType="number"
However this doesn't allow me to append anything to the EditText apart from numbers. 但是,这不允许我在数字之外添加任何内容到EditText。
I could change the XML attribute to: 我可以将XML属性更改为:
android:inputType="number|text"
but this would change the keyboard layout thus allowing the user to also enter text which I don't want. 但这会更改键盘布局,从而使用户也可以输入不需要的文本。
The "add new payment method" in the Play Store app does what I'm after but I just can't figure out how they do it. Play商店应用中的“添加新付款方式”可以满足我的要求,但我无法弄清楚他们是如何做到的。
When you use inputType="number"
it disables " "
and "-"
chars. 当您使用inputType="number"
它将禁用" "
和"-"
字符。 You can keep using this type and specify that the " "
char should be counted as a digit by specifying digits="0123456789 "
in the layout xml as well. 您可以继续使用此类型,并通过在布局xml中也指定digits="0123456789 "
来指定将" "
char计为一个数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.