android安卓屏蔽禁用系统输入法,自定义软键盘,解决EditText光标问题demo

发布时间:2020-09-23 09:33:31 作者:careylwq
来源:网络 阅读:8199

目前很多的输入法都有自动提示补全功能,在一些应用场景里不适用,需要禁用系统输入法,自定义软键盘,EditText的光标问题是比较头疼的,网上的说法很多,然而大部分都是解决不了问题的。以下是本人做的一个demo供网友参考。

直接上代码:

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;
	}

android安卓屏蔽禁用系统输入法,自定义软键盘,解决EditText光标问题demo

其他代码就不贴了,需要完整demo的请自行下载。

附件:http://down.51cto.com/data/2367320
推荐阅读:
  1. 安卓Android--PPTP教程
  2. android 安卓edittext自动弹出数字键盘

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android 安卓 禁用系统

上一篇:python hbase读取数据发送kafka的方法

下一篇:mysql怎么查看表结构

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》