自定义车牌软键盘

前人栽树后人凉

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=
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值