【问题标题】:How to show the numeric keypad如何显示数字小键盘
【发布时间】:2011-06-08 06:39:45
【问题描述】:

我阅读了其他几篇文章并使用了 input.setInputType(TYPE_NUMBER_FLAG_DECIMAL);确实打开了键盘,但不是数字键盘

这有什么诀窍吗?

【问题讨论】:

    标签: android text android-edittext


    【解决方案1】:

    android:inputType="number" 在您的 xml 文件中

    编辑:“数字”不起作用,改为“数字”(小写N)

    【讨论】:

    • 编辑视图位于使用构建器的弹出窗口中,因此没有 xml。我认为 setInputType 的作用与 XML 中的作用相同
    【解决方案2】:

    a) 在 xml 中

    android:numeric="decimal"
    

    b) 在代码中

    EditText editView = new EditText(this);
    editView.setKeyListener(new DigitsKeyListener());
    

    【讨论】:

      【解决方案3】:

      在你的 xml 中,你必须这样做:

      android:inputType="Number"
      

      在您的代码中,执行:

      editText.requestFocus();
      

      然后:

      InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
      

      我花了很多天才弄明白。我什至尝试过 editText.performClick();不工作。

      【讨论】:

      • 标志InputMethodManager.SHOW_IMPLICIT是打开EditText InputType中设置的对应类型键盘的键。谢谢!
      【解决方案4】:

      要在活动开始时弹出数字键盘,我使用了以下步骤:

      layout 中创建了编辑文本字段:

       <EditText
              ...
              android:inputType="number"    
              ...  />
      

      在函数onCreate()中显示软键盘

      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
      

      最重要的是在onResume方法中重点编辑文本。

          @Override
          public void onResume() {
              super.onResume();
              editText.setFocusableInTouchMode(true);
              editText.requestFocus();
          }
      

      【讨论】:

        【解决方案5】:

        我找到了两种简单的方法,将其中一种添加到 XML 文件中的 EditText 块中:

        1. 数字拨号键盘
                android:inputType="phone"
                android:digits="1234567890"
        
        1. 键盘的数字部分
                android:inputType="number"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-10-08
          • 2016-05-06
          • 2013-05-02
          • 2022-07-21
          • 2023-03-25
          • 1970-01-01
          • 1970-01-01
          • 2016-09-14
          相关资源
          最近更新 更多