EditText软数字键盘有时不允许数字 [英] EditText soft numeric keyboard sometimes does not allow digits
问题描述
以下代码生成一个EditText(目标版本23).我已经为此工作了大约8个小时,并且收到了一些建议,但我认为以前没有人见过,所以我仍然坚持.
The following code produces an EditText (target version 23). I've been working on this for about 8 hours, and have received some suggestions, but I don't think anyone has ever seen this before, so I remain stuck.
- 单击该字段.
- A/N软键盘打开.
- 单击123?左下角的按钮.数字软键盘打开.
- 按任意数字.什么都没发生.
- 长按5,将"5/8"添加到文本字段中.
- 按任意特殊字符,例如@.它可能会添加到该字段中.
- 清除字段.键入"for",按123 ?,现在将要输入数字.
- 清除字段.键入"for?",然后按123 ?,则不输入数字.
我添加了一个TextWatcher.如果数字未发布,则TextWatcher也不会看到它们.
I added a TextWatcher. If the digits didn't post, the TextWatcher didn't see them either.
EditText bottomT = new EditText(model);
bottomT.setTextSize(14);
bottomT.setHint("ZIP");
bottomT.setHintTextColor(Color.BLACK);
bottomT.setBackgroundColor(Color.WHITE);
bottomT.setTextColor(Color.BLACK);
// bottomT.setInputType(InputType.TYPE_CLASS_NUMBER) Didn't make any difference.
// bottomT.setRawInputType(InputType.TYPE_CLASS_NUMBER) Didn't make any difference.
// bottomT.setText("", TextView.BufferType.EDITABLE); DIdn't make a difference
bottomT.setText("");
推荐答案
EditText行为异常,因为在我的自定义ViewGroup中,我拥有
EditText is misbehaving because in my custom ViewGroup I had
protected void onLayout(boolean changed, int l, int t, int r, int b)
{
....
child.layout(child.getLeft(), child.getTop(),
child.getLeft() + child.getMeasuredWidth(),
child.getTop() + child.getMeasuredHeight());
child.setRight(somevalue); // CAUSES EDITTEXT PROBLEMS
child.setBottom(somevalue); // CAUSES EDITTEXT PROBLEMS
现在很清楚,我无法设置setRight()和setBottom(),但是也很清楚,EditText应该不会变得很奇怪.
It’s clear now that I can't setRight() and setBottom(), but it’s also clear that EditText should not get weird.
忽略退格键.
随机忽略数字键,但接受小数点.
Randomly ignore numeric keys, but accept the decimal point.
忽略newLine(Enter)键
Ignore the newLine(Enter) key
是否忽略哪个键取决于设备.三星Tab 4或Nexus 5 API 23 X86模拟器是了解这一点的好地方.
Which keys are ignored, or not, depends on the device. Samsung Tab 4 or the Nexus 5 API 23 X86 emulator are good places to see this.
这篇关于EditText软数字键盘有时不允许数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!