android EditText 的键盘弹出(不弹出)坑爹
16lz
2021-12-04
需求:如果想要不弹出键盘并且失去光标,
在layout布局文件里,在EditText的父布局中加上两个属性(我是直接加载顶层控件上)
android:focusable="true"android:focusableInTouchMode="true"
缺点:当你点击 EditText 的时候键盘弹不起来
解决方法:给EditText 添加点击事件
edit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SoftInputUtil.showKeyBoard(edit); }});
public static void showKeyBoard(final EditText editText) { if (editText != null) { editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { try { InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(editText, 0); } catch (Exception e) { e.printStackTrace(); } } }, 300); }}
另一种方式:在布局里面多放一个edittext ,用布局遮挡住, 让光标在它身上,然后关闭键盘 也可以实现;
更多相关文章
- Android平台上面输入法遮挡问题-android:windowSoftInputMode属
- Android横竖屏切换
- Android(安卓)搜索 把软键盘上的回车键改为搜索
- Android禁止EditText自动弹出软键盘的方法及遇到问题
- Failed to fetch URL http://dl-ssl.google.com/android/reposit
- android基础入门(一)——搭建android开发平台创建模拟机AVD
- 搭建 Android(安卓)开发环境,初试HelloWorld (win7) (下)
- Android(安卓)开发小技巧1: Button 点击区域过小
- This text field does not specify an inputType or a hint