How do I use InputType=numberDecimal with the “phone” soft keypad?

后端 未结 5 1263
不知归路
不知归路 2021-02-01 18:59

For an EditText box, the user should only be entering valid numbers, so I am using android:inputType=\"numberDecimal\". Unfortunately, the soft keyboar

5条回答
  •  情深已故
    2021-02-01 19:16

    Adam Dunn code works perfect, but didnt show how to implement the class

    import android.text.method.DigitsKeyListener;
    import android.text.InputType;
    public class CustomDigitsKeyListener extends DigitsKeyListener
    {
        public CustomDigitsKeyListener() {
            super(false, false);
        }
    
        public CustomDigitsKeyListener(boolean sign, boolean decimal) {
            super(sign, decimal);
        }
    
        public int getInputType() {
            return InputType.TYPE_CLASS_PHONE;
        }
    }
    

    then you have to instance like this

    MyTextView.setKeyListener(new CustomDigitsKeyListener(true,true));
    

提交回复
热议问题