zoukankan      html  css  js  c++  java
  • 关于Edittext默认弹出软键盘为数字键

    如果说我们只是输入数字的话,我们可以直接在xml文件中:

    android:inputType="number"
    

    如果是身份证类型的话,我们可以这样:

    android:inputType="number"
    android:digits="0123456789xyzXYZ"
    

    我们也可以在java文件中这样:

      EditText et = new EditText(this);
            et.setKeyListener(new NumberKeyListener() {
                // 0无键盘 1英文键盘 2模拟键盘 3数字键盘
                @Override
                public int getInputType() {
                    // TODO Auto-generated method stub
                    return 3;
                }
    
                // 返回允许输入的字符
                @Override
                protected char[] getAcceptedChars() {
                    // TODO Auto-generated method stub
                    char[] c = {'a', 'b', 'c', 'd', 'e', '1', '2'};
                    return c;
                }
              });
    

    如果是和默认类型一样,可以输入任意字符的话,我们可以这样,和上面的实现方式类似,只不过将 NumberKeyListener 换成了 TextKeyListener 而已:

     EditText et = new EditText(this);
            et.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.NONE, true) {
                @Override
                public int getInputType() {
                    return InputType.TYPE_CLASS_PHONE;
                }
            });
    

    这样就可以啦!

    由于本人水平有限,文中如有错误欢迎批评指正,小弟感激不尽!

    最后,感谢兔子家的三哥(http://www.jianshu.com/u/87ae381f8e5b)对我工作的帮助和指导,谢谢!

      

      

  • 相关阅读:
    bzoj 1017 魔兽地图DotR
    poj 1322 chocolate
    bzoj 1045 糖果传递
    poj 3067 japan
    timus 1109 Conference(二分图匹配)
    URAL 1205 By the Underground or by Foot?(SPFA)
    URAL 1242 Werewolf(DFS)
    timus 1033 Labyrinth(BFS)
    URAL 1208 Legendary Teams Contest(DFS)
    URAL 1930 Ivan's Car(BFS)
  • 原文地址:https://www.cnblogs.com/Talon-lly/p/6526627.html
Copyright © 2011-2022 走看看