软键盘默认不弹出,点击别的控件让EditText获得焦点并弹出软键盘

软键盘默认不弹出

两种方法,一个是在清单文件里加句话。
1、** android:windowSoftInputMode="stateAlwaysHidden"**


Paste_Image.png

设置软键盘默认不弹出。
2、第二个是将焦点转移。在其父布局上写
```
android:focusable="true"
android:focusableInTouchMode="true"

![Paste_Image.png](http://upload-images.jianshu.io/upload_images/3161958-db8289519c23ce73.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


之后,新的要求。想:
点击别的控件让EditText获得焦点并弹出软键盘
则,分两步:
1、控件重新获得焦点

packCount.setFocusable(true);
packCount.setFocusableInTouchMode(true);
packCount.requestFocus();

2、打开软键盘

InputMethodManager imm = (InputMethodManager) packCount.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0,InputMethodManager.SHOW_FORCED);

![Paste_Image.png](http://upload-images.jianshu.io/upload_images/3161958-165955807bcde2ee.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


还有一个让Edittext的焦点移动到指定位置。
editText.setSelection(editText.getText().toString().length());
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容