[英]EditText soft numeric keyboard sometimes does not allow digits
The following code produces an EditText (target version 23).以下代码生成一个 EditText(目标版本 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.我已经为此工作了大约 8 个小时,并收到了一些建议,但我认为以前没有人见过这种情况,所以我仍然被卡住了。
I added a TextWatcher.我添加了一个 TextWatcher。 If the digits didn't post, the TextWatcher didn't see them either.如果数字没有发布,TextWatcher 也不会看到它们。
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 is misbehaving because in my custom ViewGroup I had EditText 行为不端,因为在我的自定义 ViewGroup 中我有
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
It's clear now that I can't setRight() and setBottom(), but it's also clear that EditText should not get weird.现在很清楚我不能 setRight() 和 setBottom(),但也很清楚 EditText 不应该变得奇怪。
Ignore the backspace key.忽略退格键。
Randomly ignore numeric keys, but accept the decimal point.随机忽略数字键,但接受小数点。
Ignore the newLine(Enter) key忽略 newLine(Enter) 键
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.三星 Tab 4 或 Nexus 5 API 23 X86 模拟器是查看此内容的好地方。
您必须在 Java 代码中添加这一行。
bottomT.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
试试这行代码。
bottomT.setInputType(InputType.TYPE_CLASS_NUMBER |InputType.TYPE_NUMBER_FLAG_DECIMAL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.