简体   繁体   English

Android EditText InputType,数字键盘+附加文本

[英]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.

相关问题 没有EditText的Android键盘InputType - Android keyboard InputType without EditText Android如何使用InputType =“ text”的EditText显示数字软键盘 - Android How to show numeric softkeyboard with EditText of InputType=“text” Gboard键盘:数值inputType在ListView中的EditText上不起作用 - Gboard Keyboard: Numeric inputType not working on EditText in ListView Android EditText 数字键盘 - Android EditText numeric keyboard EditText键盘输入类型问题 - EditText Keyboard Inputtype issue 即使我将inputType设置为数字edittext android,也会出现文本键盘 - text keyboard appear even if I have set inputType to number edittext android android EditText用什么inputType避免文本提示 - android EditText what inputType to avoid text suggestions EditText android:numeric =“decimal”和android:inputType =“numberDecimal”之间的区别 - Difference among EditText android:numeric=“decimal” and android:inputType=“numberDecimal” Android EditText inputType =“ numberDecimal”仅在第二次点击时显示正确的键盘 - Android EditText inputType=“numberDecimal” only shows correct keyboard on second tap 如何使用 inputType 'DATE' 修复 EditText 在键盘 android 中不显示/? - How to fix EditText with inputType 'DATE' don't show / in keyboard android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM