Disable soft keyboard on NumberPicker

前端 未结 11 1113
庸人自扰
庸人自扰 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 18:51

    Just enhanced the @MaxVogler 's ans (so if wannt vote this vote @MaxVogler too) and make it a robust hack. Also we dont need to call setOnFocusChangeListener and setInputType. Only setFocusable to false will do.

    Below is a helper api to enable/disable the feature

    public static void enableNumberPickerManualEditing(NumberPicker numPicker,
            boolean enable) {
        int childCount = numPicker.getChildCount();
    
        for (int i = 0; i < childCount; i++) {
            View childView = numPicker.getChildAt(i);
    
            if (childView instanceof EditText) {
                EditText et = (EditText) childView;
                et.setFocusable(enable);
                return;
            }
        }
    }
    

提交回复
热议问题