android keyboardview去掉点击效果,KeyboardView is deprecated in android

问题

KeyboardView has been deprecated official by android team in API level 29 and i didn't able to find the alternative way for this. Please let me know if there any alternative?

回答1:

From the docs here :

This class was deprecated in API level 29. This class is deprecated

because this is just a convenient UI widget class that application

developers can re-implement on top of existing public APIs. If you

have already depended on this class, consider copying the

implementation from AOSP into your project or re-implementing a

similar widget by yourselves

This means that you have to create your own view with all the keys, which also means handling all the click events like enter, delete and switching keyboards eg. to symbols etc. by yourself.

Actually there are many ways to do it. But I will try to give you a simple idea, you will follow most of the steps that you used while using the deprecated KeyboardView:

First create your custom keyboard layout with android:layout_height="wrap_content", you can use any layout depending what is convenient for you like LinearLayout, RelativeLayout and Buttons for the keys. I used a GridLayout with Buttons.

Then create the subclass of InputMethodService as usual:

public class MyIMService extends InputMethodService implements View.OnClickListener {

private static String TAG = "MyIMService";

@Override

public View onCreateInputView() {

View myKeyboardView = getLayoutInflater().inflate(R.layout.key_layout, null);

Button btnA = myKeyboardView.findViewById(R.id.btnA);

btnA.setOnClickListener(this);

//ADD ALL THE OTHER LISTENERS HERE FOR ALL THE KEYS

return myKeyboardView;

}

@Override

public void onClick(View v) {

//handle all the keyboard key clicks here

InputConnection ic = getCurrentInputConnection();

if (v instanceof Button) {

String clickedKeyText = ((Button) v).getText().toString();

ic.commitText(clickedKeyText, 1);

}

}

}

The key_layout should contains all the keys can be any layout, I used a GridLayout which resembles a typical keyboard. For switching between symbols or numbers you should update the text of the buttons etc. As I said earlier you can try a different way of handling all the click events. But this should give you the basic idea.

That's it. You have to add this service in your manifest file as usual and also the other steps as usual. This should work now.

来源:https://stackoverflow.com/questions/60316785/keyboardview-is-deprecated-in-android

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/416258.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

浅析dedecms织梦网站留言板提交时验证码错误的解决办法

默认情况下,如果我们使用DEDE模板中的默认留言板时,如果留言信息不正确或者输入内容为空时,dedecms系统就会返回一个空 白页。这样的方式很不利于用户体验,解决这个问题实际上非常简单。 找到dedecms留言板文件/plus/guestbook.ph…

Tomcat服务器的安装及配置

学习目标: 了解Tomcat服务器的主要作用掌握Tomcat服务器的安装与配置掌握Tomcat安装目录下主要文件夹的作用jsp的执行流程1.Web的工作原理流程图:从图中可以看出Tomcat服务器的主要作用就是接受客户端的请求和响应。 2.jsp执行流程 1)客户端发…

android 后台执行js,android - 当应用程序在后台运行时,Android WebView消耗大量电能...

我的Android应用程序中有一个WebView,并且此WebView运行的网站上带有相当多的Javascript。当我的应用程序在后台运行时,用户报告了高功耗,我希望这是由于此javascript。但是,我不想完全卸载或删除WebView,因为这会影响…

织梦DEDE网站后台如何上传附件

首先登录织梦网站后台: 分别点击 核心 — 附件管理 — 文件式管理 里面有织梦自带的几个文件夹,包括图片,视频,软件等文件夹。我们来新建一个file文件夹 点击 新建目录 建立file文件夹。 默认应该是跳转进file文件夹了&#xff…

Hands-On Modeler (建模人员参与程序开发)

如果编写代码的人员认为自己没必要对模型负责,或者不知道让模型为应用程序服务,那么这个模型就和程序没有任何关联.如果开发人员没有意识到改变代码就意味着改变模型,那么他们对程序的重构不但不会增强模型的作用,反而会削弱他的效果, 同样,如果建模人员不参与到程序的实现过程…

泰拉瑞亚mod鸿蒙方舟,三款高评分的沙盒生存类手游,经典之作泰拉瑞亚你有玩过吗?...

沙盒类游戏由一个或多个地图区域构成,往往包含多种游戏要素,包括角色扮演,动作、射击、驾驶等等。能够改变或影响甚至创造世界是沙盒游戏的特点。自由度高也成为了沙盒游戏的一个标配,所以今天小皮就给大家推荐几款超赞的沙盒生存…

织梦返回上一页面

ShowMsg("成功退出登录!","javascript:history.back(-1)",0,2000); ShowMsg("成功退出登录!",$_SERVER[HTTP_REFERER],0,2000); $_SERVER[HTTP_REFERER] 是上一页的url

android任务 进程 线程详解,Android任务、进程、线程详解

singleTop模式,基本上于standard分歧,仅正在请求的Activity反好位于栈顶时,无所区别。此时,配放成singleTop的Activity,不再会构制新的实例加入到Task栈外,而是将新来的Intent发送到栈顶Activity外&#xf…

截取地址栏URL参数

UrlParm function() { // url参数var data, index;(function init() {data [];index {};var u window.location.search.substr(1);if(u ! ) {var parms decodeURIComponent(u).replace(/&/g,"&").split(&);for(var i 0, len parms.length; i …

android 清理缓存 简书,分享:Android清除本地数据缓存代码

/**文 件 名:DataCleanManager.java*描述:主要功能有清除内/外缓存,清除数据库,清除sharedPreference,清除files和清除自定义目录*/importjava.io.File;importandroid.content.Context;importandroid.os.Environment;/** *本应用数据清除管理…

[AH/HNOI2017]大佬

题目描述 人们总是难免会碰到大佬。他们趾高气昂地谈论凡人不能理解的算法和数据结构,走到任何一个地方,大佬的气场就能让周围的人吓得瑟瑟发抖,不敢言语。 你作为一个 OIER,面对这样的事情非常不开心,于是发表了对大佬…

csdn markdown 编辑器开启

1、打开我的博客网址https://mp.csdn.net/ 2、在博客设置栏目中勾选markdown,并且选择自己喜欢的主题 3、保存

html检查输入为空,html input输入验证不为空

html5的话使用required即可,比较简单。但是ie10以下的浏览器没有required特性。所以就要靠其他方式来对用户输入做验证。下面是利用js的方法:function validate(){var domain document.getElementById(domain).value;var domainInfo document.getEleme…

Nagle算法延时确认

数据流分类成块数据交互数据Rlogin需要远程系统(服务器)回显我们(客户)键入的字符数据字节和数据字节的回显都需要对方确认rlogin 每次只发送一个字节到服务器,而Telnet 可以选择发送一行数据确认是通过期望数据序号Na…

Mac下Apache使用

Mac下Apache使用 1、常用操作 开启、重启、关闭 sudo apachectl start sudo apachectl restart sudo apachectl stop 2、打开Apache目录 cd /private/etc/apache2 && open . 3、打开web目录 cd /Library/WebServer/Documents && open .

考研计算机专业课统考吗,【计算机考研】你了解计算机统考408吗?

原标题:【计算机考研】你了解计算机统考408吗?什么是408计算机统考计算机考研专业课在2009年年初实行了第一次统考,统考是国家教育部出题,全国统一考试,计算机考研统考编号是408,408考试科目包括&#xff1…