Disable soft keyboard on NumberPicker

前端 未结 11 1121
庸人自扰
庸人自扰 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条回答
  •  Happy的楠姐
    2020-12-22 18:44

    /**
     * set focus to top level window
     * disposes descendant focus
     * disposes softInput
     * @param context - activity context
     * @param enable - state of focus
     * */
    public static void topLevelFocus(Context context, boolean enable){
        if(Activity.class.isAssignableFrom(context.getClass())){
            ViewGroup tlView = (ViewGroup) ((Activity) context).getWindow().getDecorView();
            if(tlView!=null){
                tlView.setFocusable(enable);
                tlView.setFocusableInTouchMode(enable);
                tlView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
                tlView.requestFocus();
            }
        }
    }
    

    * calling this:

    • will not block descendant focusability (numberpicker will be editable)

    • will hide soft input on create

    • before (processing input) getValue() will allow to get proper walue


提交回复
热议问题