zoukankan      html  css  js  c++  java
  • 阻止点击numberpicker(edittext)时候弹出输入法

    1.首先说说默认不显示输入法,这里通常又三种:

    在 AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为 adjustUnspecified|stateHidden


      < activity android:name=".Main"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustUnspecified|stateHidden"
        android:configChanges="orientation|keyboardHidden">  //这里我没有输入也是可以的
      < intent-filter>
        < action android:name="android.intent.action.MAIN" />
        < category android:name="android.intent.category.LAUNCHER" />
      < /intent-filter>
      < /activity>

    方法二:

      让 EditText失去焦点,使用EditText的clearFocus方法

      例如:
    EditText edit=(EditText)findViewById(R.id.edit);
      edit.clearFocus();

    方法三:

      强制隐藏Android输入法窗口

    例如:
      EditText edit=(EditText)findViewById(R.id.edit);
      InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(edit.getWindowToken(),0);

      然后就说说numberpicker。找个是android3.0之后才有的一个控件,总的来说并不美观(很多人会用想numberwheelpicker之类的控件),但还是蛮使用的。很多情况下并不希望点击numberpicker时候弹出输入法。所以又下面的解决办法,本质还是处理edittext哦:

    numberPicker = (NumberPicker)findViewById(R.id.numPicker);
            numberPicker.setMaxValue(100);
            numberPicker.setMinValue(0);
            numberPicker.setWrapSelectorWheel(false);
            String[] nums = new String[100];
            for(int i=0; i<nums.length; i++)
               nums[i] = Integer.toString(i);
            numberPicker.setDisplayedValues(nums);
            numberPicker.setFocusable(false);
            numberPicker.setValue(1);
            ((EditText) numberPicker.getChildAt(1)).setOnFocusChangeListener(new OnFocusChangeListener() {
                
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    // do nothing
                }
            });
            // Suppress soft keyboard from the beginning
            ((EditText) numberPicker.getChildAt(1)).setInputType(InputType.TYPE_NULL);
  • 相关阅读:
    python的函数
    Python的条件语句和循环语句
    Python的输入与输出
    Python变量和类型
    Python的运算符
    Python的注释
    pycharm基本使用
    推特史上最大规模黑客入侵案:17岁问题少年的隐秘人生
    进程和线程的区别及线程的介绍
    python接口自动化42
  • 原文地址:https://www.cnblogs.com/slider/p/2973635.html
Copyright © 2011-2022 走看看