哦然间发现了android.inputmethodservice.Keyboard类,即android可以自定义键盘类,做了一个简单例子供大家参考,

首先看看效果图:

键盘内容布局:keycontent.xml

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"android:keyWidth="25%p"android:horizontalGap="0px"android:verticalGap="0px"android:keyHeight="50dip"><Row><Key android:codes="49" android:keyLabel="1" /><Key android:codes="50" android:keyLabel="2" /><Key android:codes="51" android:keyLabel="3" /><Key android:codes="57419"android:keyEdgeFlags="right"android:keyIcon="@drawable/keyboard_capslock" /></Row><Row><Key android:codes="52" android:keyLabel="4" /><Key android:codes="53" android:keyLabel="5" /><Key android:codes="54" android:keyLabel="6" /><Key android:codes="57421"android:keyEdgeFlags="right"android:keyIcon="@drawable/keyboard_big_capslock" /></Row><Row><Key android:codes="55" android:keyLabel="7" /><Key android:codes="56" android:keyLabel="8" /><Key android:codes="57" android:keyLabel="9" /><Key android:codes="-5"android:keyEdgeFlags="right"android:isRepeatable="true"android:keyLabel="delete"android:keyIcon="@drawable/keyboard_delete" /></Row><Row><Key android:codes="-3" android:keyIcon="@drawable/keyboard_return" /><Key android:codes="48" android:keyLabel="0" /><Key android:codes="88" android:keyLabel="X" /></Row>
</Keyboard>

键盘布局 keyboardview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="wrap_content"><EditText android:id="@+id/edit"android:layout_width="fill_parent"android:layout_height="wrap_content"/><android.inputmethodservice.KeyboardViewandroid:id="@+id/keyboard_view"android:visibility="gone"android:focusable="true"android:focusableInTouchMode="true"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true" />
</RelativeLayout>

KeyboardActivity;

package com.pioneersoft.temp;import android.app.Activity;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;public class KeyboardActivity extends Activity{EditText edit;KeyboardView keyboardView;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.keyboardview);edit = (EditText)findViewById(R.id.edit);edit.setInputType(InputType.TYPE_NULL);edit.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {showKeyboard();}});keyboardView = (KeyboardView)findViewById(R.id.keyboard_view);keyboardView.setKeyboard(new Keyboard(this, R.layout.keycontent));keyboardView.setEnabled(true);keyboardView.setPreviewEnabled(true);keyboardView.setOnKeyboardActionListener(new OnKeyboardActionListener() {@Overridepublic void onKey(int primaryCode, int[] keyCodes) {Editable editable = edit.getText();int start = edit.getSelectionStart();if (primaryCode == Keyboard.KEYCODE_CANCEL) {hideKeyboard();} else if (primaryCode == Keyboard.KEYCODE_DELETE) {if (editable != null && editable.length() > 0) {editable.delete(start - 1, start);}} else if (primaryCode == 57419) { // go leftif (start > 0) {edit.setSelection(start - 1);}} else if (primaryCode == 57421) { // go rightif (start < edit.length()) {edit.setSelection(start + 1);}} else {editable.insert(start, Character.toString((char)primaryCode));}}@Overridepublic void onPress(int primaryCode) {// TODO Auto-generated method stub}@Overridepublic void onRelease(int primaryCode) {// TODO Auto-generated method stub}@Overridepublic void onText(CharSequence text) {// TODO Auto-generated method stub}@Overridepublic void swipeDown() {// TODO Auto-generated method stub}@Overridepublic void swipeLeft() {// TODO Auto-generated method stub}@Overridepublic void swipeRight() {// TODO Auto-generated method stub}@Overridepublic void swipeUp() {// TODO Auto-generated method stub}});}private void showKeyboard() {int visibility = keyboardView.getVisibility();if (visibility == View.GONE || visibility == View.INVISIBLE) {keyboardView.setVisibility(View.VISIBLE);}}private void hideKeyboard() {int visibility = keyboardView.getVisibility();if (visibility == View.VISIBLE) {keyboardView.setVisibility(View.INVISIBLE);}}}

以上就是自定义键盘布局的内容,如需详细内容需要参考api。

android 自定义软键盘相关推荐

  1. android自定义系统键盘,Android自定义软键盘

    [实例简介] Android自定义软键盘 [实例截图] [核心代码] keydemo └── keydemo ├── AndroidManifest.xml ├── bin │   ├── class ...

  2. Android 自定义软键盘实现 数字九宫格

    前言 最近项目在对接美团外卖功能 实现外面小哥凭取货码取货 对接完功能后 用户反馈 弹出的软键盘 很难输入 数字太小了 大概是下面这种显示方式 需求 组长说 要不搞一个自定义软键盘吧 数字搞大点 方便 ...

  3. Android自定义软键盘输入法,隐藏系统输入法显示光标的实现

    android实现自定义软键盘,先上图看效果,效果基本上是仿ios输入法实现的 这里是实现隐藏系统输入法,同时让EditText能获取光标的代码部分(通过反射调用): <span style=& ...

  4. Android自定义软键盘样式:字母、数字、标点三种切换

    先看效果图: 1.在需要的调用软键盘的activity_mian.xml中加入键盘控件 <!--自定义键盘控件--> <RelativeLayoutandroid:layout_wi ...

  5. android自动软键盘,Android自定义软键盘

    MyKeyboard Android自定义键盘的使用 实现步骤 第一步: 1.新建一个xml文件夹放在res目录下面,然后新建xml文件:money_keyboard.xml 2.然后在XML文件中添 ...

  6. Android 自定义软键盘实现 数字九宫格,2021年Android常见面试题目

    实现效果GIF 实现代码 自定义View 一个NineNumericKeyboardView /** Author by Lyu Date on 2021/5/26-19:55 Description ...

  7. Android 自定义软键盘实现

    module链接:https://download.csdn.net/download/meixi_android/10652565 compile project(':edlibrary') , ' ...

  8. android自定义键盘开源,Android自定义软键盘的设计与实现代码

    偶然间发现了Android.inputmethodservice.Keyboard类,即android可以自定义键盘类,做了一个简单例子供大家参考. 效果如下: 先看界面布局文件 android:la ...

  9. Android自定义软键盘的实现

    先看界面布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and ...

最新文章

  1. python后端学什么框架_献给正在学习python的你, 10个最受欢迎的Python开源框架
  2. 记录一下,Sqlite,用GB系列编码排序时是按拼音,UTF-8排序是按笔画
  3. [LeetCode][JavaScript]Invert Binary Tree 反转二叉树
  4. 从阿里前端工程化中台实践,看中台建设的舍与得
  5. PLSQL DBMS_DDL.ANALYZE_OBJECT
  6. 慎用JSON.stringify
  7. 密码学--CTF Crypto
  8. 英语国际音标发音——见标能读
  9. 地域和地方的区别_地方、地域、地区、地面、地段的区别_近义词词典_词林在线词典...
  10. Mil学习之 MimArith 图片逻辑运算
  11. 数据结构习题——第一章 绪论
  12. 李四光预测的地震带及合肥地震分析
  13. 135微信编辑器html模式,135微信编辑器官网【设置思路】
  14. Flutter-Container详解
  15. 【转】do{...}while(0)的意义和用法
  16. Image Processing and Analysis_8_Edge Detection:Finding Edges and Lines in Images by Canny——1983...
  17. 从失败中崛起!52岁斯皮尔曼,曾携华人科学家2次斩获哥德尔奖
  18. vl6180开发记录
  19. 上大学后才知道的14件事
  20. 马云在阿里巴巴上市庆祝晚宴上的演讲

热门文章

  1. 用友U8案例教程采购报表
  2. IPTV、DVB、OTT的区别
  3. GDKOI 2017 滚粗记
  4. 给内网映射增加安全防护
  5. SSL certificate problem: unable to get local issuer certificate解决办法
  6. 卧槽,3D错觉!这脑洞简直了...
  7. android开发 wifi功率,一种基于Android系统的功耗计算方法与流程
  8. springboot jar包 一键部署,开机自动启动
  9. 搭建微服务架构的电商平台系统
  10. 欧姆龙CP1H+CIF11与海利普变频器modbus通讯