[英]EditText soft numeric keyboard sometimes does not allow digits
以下代碼生成一個 EditText(目標版本 23)。 我已經為此工作了大約 8 個小時,並收到了一些建議,但我認為以前沒有人見過這種情況,所以我仍然被卡住了。
我添加了一個 TextWatcher。 如果數字沒有發布,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 行為不端,因為在我的自定義 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
現在很清楚我不能 setRight() 和 setBottom(),但也很清楚 EditText 不應該變得奇怪。
忽略退格鍵。
隨機忽略數字鍵,但接受小數點。
忽略 newLine(Enter) 鍵
忽略或不忽略哪些鍵取決於設備。 三星 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.