Disable soft keyboard on NumberPicker

前端 未结 11 1157
庸人自扰
庸人自扰 2020-12-22 18:20

I\'m trying to deactivate the soft keyboard when using a NumberPicker to enter numerical values (for aesthetic reasons). This is my layout-xml-code:



        
11条回答
  •  余生分开走
    2020-12-22 19:05

    After reading through the com/android/internal/widget/NumberPicker.java source code i got to the following solution:

    // Hide soft keyboard on NumberPickers by overwriting the OnFocusChangeListener
    OnFocusChangeListener fcl = new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            // Do nothing to suppress keyboard
        }
    };
    
    ((EditText) numberPicker.getChildAt(1)).setOnFocusChangeListener(fcl);
    
    // Suppress soft keyboard from the beginning
    ((EditText) numberPicker.getChildAt(1)).setInputType(InputType.TYPE_NULL);
    

提交回复
热议问题