前人栽树后人凉
2015年的一篇文章,公布了核心代码,源码下载需要5C币。
Android 一个简易的自定义软键盘
2018年的一篇文章,在15年文章的基础上,公布了绝大多数代码,源码托管在Github上。
Android 自定义车牌键盘
这文章虽然是自己写的,但核心思想和代码还是离不开前辈们的基础,在此致谢!!
总的说要自定义软键盘,要解决三件事:
1.软键盘元素和布局制作。
2.软键盘弹起、消失和具体操作。
3.系统键盘的抑制。
下面来详细说一下:
一、软键盘的制作需要Keyboard类型的XML文件内部用Row,来详细规定一共有几行,每行有什么元素,以及元素的位置和编号。
由于是车牌,所以涉及:1.省简称
,2.大写字母A-Z
,3.数字0-9
。布局的设计是省简称一组,数字字母另一组,所以需要两组布局。
第一组省简称:province_abbreviation.xml
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="0.0px"
android:keyHeight="8%p"
android:keyWidth="10%p"
android:verticalGap="0.0px">
<Row android:verticalGap="1%p">
<Key
android:codes="20140"
android:horizontalGap="1%p"
android:keyEdgeFlags="left"
android:keyLabel="京"
android:keyWidth="8%p" />
<Key
android:codes="27941"
android:horizontalGap="2%p"
android:keyLabel="津"
android:keyWidth="8%p" />
<Key
android:codes="20864"
android:horizontalGap="2%p"
android:keyLabel="冀"
android:keyWidth="8%p" />
<Key
android:codes="40065"
android:horizontalGap="2%p"
android:keyLabel="鲁"
android:keyWidth="8%p" />
<Key
android:codes="26187"
android:horizontalGap="2%p"
android:keyLabel="晋"
android:keyWidth="8%p" />
<Key
android:codes="33945"
android:horizontalGap="2%p"
android:keyLabel="蒙"
android:keyWidth="8%p" />
<Key
android:codes="36797"
android:horizontalGap="2%p"
android:keyLabel="辽"
android:keyWidth="8%p" />
<Key
android:codes="21513"
android:horizontalGap="2%p"
android:keyLabel="吉"
android:keyWidth="8%p" />
<Key
android:codes="40657"
android:horizontalGap="2%p"
android:keyLabel="黑"
android:keyWidth="8%p" />
<Key
android:codes="27818"
android:horizontalGap="2%p"
android:keyEdgeFlags="right"
android:keyLabel="沪"
android:keyWidth="8%p" />
</Row>
<Row android:verticalGap="1%p">
<Key
android:codes="33487"
android:horizontalGap="1%p"
android:keyEdgeFlags="left"
android:keyLabel="苏"
android:keyWidth="8%p" />
<Key
android:codes="27993"
android:horizontalGap="2%p"
android:keyLabel="浙"
android:keyWidth="8%p" />
<Key
android:codes="30358"
android:horizontalGap="2%p"
android:keyLabel="皖"
android:keyWidth="8%p" />
<Key
android:codes="38397"
android:horizontalGap="2%p"
android:keyLabel="闽"
android:keyWidth="8%p" />
<Key
android:codes="36195"
android:horizontalGap="2%p"
android:keyLabel="赣"
android:keyWidth="8%p" />
<Key
android:codes="35947"
android:horizontalGap="2%p"
android:keyLabel="豫"
android:keyWidth="8%p" />
<Key
android:codes="37122"
android:horizontalGap="2%p"
android:keyLabel="鄂"
android:keyWidth="8%p" />
<Key
android:codes="28248"
android:horizontalGap="2%p"
android:keyLabel="湘"
android:keyWidth="8%p" />
<Key
android:codes="31908"
android:horizontalGap="2%p"
android:keyLabel="粤"
android:keyWidth="8%p" />
<Key
android:codes="26690"
android:horizontalGap="2%p"
android:keyEdgeFlags="right"
android:keyLabel="桂"
android:keyWidth="8%p" />
</Row>
<Row android:verticalGap="1%p">
<Key
android:codes="28189"
android:horizontalGap="11%p"
android:keyEdgeFlags="left"
android:keyLabel=