android安卓屏蔽禁用系统输入法,自定义软键盘,解决EditText光标问题demo
2016-01-21 11:59
886 查看
目前很多的输入法都有自动提示补全功能,在一些应用场景里不适用,需要禁用系统输入法,自定义软键盘,EditText的光标问题是比较头疼的,网上的说法很多,然而大部分都是解决不了问题的。以下是本人做的一个demo供网友参考。
直接上代码:
xml软键盘:
其他代码就不贴了,需要完整demo的请自行下载。
附件:http://down.51cto.com/data/2367320
直接上代码:
xml软键盘:
<android.inputmethodservice.KeyboardView android:id="@+id/keyboard_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/white" android:focusable="true" android:focusableInTouchMode="true" android:keyBackground="@drawable/btn_keyboard_key" android:keyTextColor="@color/black" android:visibility="gone" />禁用系统输入法,解决EditText光标问题的重要代码:
public boolean onTouch(View v, MotionEvent event) { //隐藏输入法,显示光标 EditText et=(EditText)v; int inType = et.getInputType(); // back up the input type if (sdkInt>=11) { Class<EditText> cls=EditText.class; try { Method setShowSoftInputOnFocus=cls.getMethod("setShowSoftInputOnFocus", boolean.class); setShowSoftInputOnFocus.setAccessible(false); setShowSoftInputOnFocus.invoke(et, false); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } }else { et.setInputType(android.text.InputType.TYPE_NULL); // disable soft input et.setInputType(inType); } keyboardUtil=null; keyboardUtil = new KeyboardUtil(act, ctx, et); et.onTouchEvent(event);// call native handler // restore input type keyboardUtil.showKeyboard(); return true; }
其他代码就不贴了,需要完整demo的请自行下载。
附件:http://down.51cto.com/data/2367320
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories