inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY);

1、//隐藏软键盘

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WidgetSearchActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

2、//显示软键盘,控件ID可以是EditText,TextView

((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).showSoftInput(控件ID,0);

3、不自动弹出键盘:

带有EditText控件的在第一次显示的时候会自动获得focus,并弹出键盘,如果不想自动弹出键盘,有两种方法:

方法一:在mainfest文件中把对应的activity设置

android:windowSoftInputMode="stateHidden" 或者android:windowSoftInputMode="stateUnchanged"

方法二:可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus

注意TextView不要设置Visiable=gone,否则会失效

,可以在布局中放一个隐藏的TextView,然后在onCreate的时候requsetFocus

注意TextView不要设置Visiable=gone,否则会失效

<TextView

android:id="@+id/text_notuse"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:focusable="true"

android:focusableInTouchMode="true"

/>

TextView textView = (TextView)findViewById(R.id.text_notuse);

textView.requestFocus();

EditText 不弹出软件键盘

方法一:

在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);
2.EditText始终不弹出软件键盘
例:
EditText edit=(EditText)findViewById(R.id.edit); edit.setInputType(InputType.TYPE_NULL);

// 默认软键盘不弹出 getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

在OnCreate()函数中,加上即可,OK,搞定

更多相关文章

  1. android中隐藏以及显示软键盘代码
  2. 分享方法:android 获得屏幕状态
  3. Android studio 实现圆形ImageView的方法步骤
  4. Android View之对现有控件进行拓展实例
  5. Android上SD卡图片的标准缓存方法
  6. android朋友圈监听键盘状态 点击空白区域隐藏键盘

随机推荐

  1. [Android记录]Android(安卓)Studio问题记
  2. android使用Toast时出现的错误
  3. Android(安卓)Weekly Notes Issue #241
  4. Android和H5交互一篇就够了
  5. Android提高篇之自定义dialog实现process
  6. Android使用Gradle依赖配置compile、impl
  7. LibGDX学习-LibGDX基本框架
  8. Android(安卓)屏幕旋转问题
  9. Android启动后,加载的2类service (Native
  10. Delphi10.2.3部署Android