1. 简介
本篇博客将实现一个自定义软键盘实现数字录入的小Demo,也是为之后可能遇到的输入手机号,支付键盘等做一些知识上的储备,也是希望能够帮到处于学习的同学,在写的不对的地方希望各位能够指出来。含有demo
2. 效果
3.实现
第一步设置 keyboard对应的xml文件,实现键盘值的排列。在res 资源文件下新建xml文件夹,新增keyboard_xml 如下内容。
具体的宽高也是可以自行去进行调整的。这里需要注意code值的赋予,因为在后面点击事件包括view绘制都用到该数值。
<?xml version="1.0" encoding="utf-8"?>
<Keyboard android:keyWidth="25.0%p" android:keyHeight="9.599996%p" android:horizontalGap="0.0px" android:verticalGap="0.0px"
xmlns:android="http://schemas.android.com/apk/res/android">
<Row>
<Key android:codes="49" android:keyLabel="1" />
<Key android:codes="50" android:keyLabel="2" />
<Key android:codes="51" android:keyLabel="3" />
<Key android:keyHeight="19.200003%p" android:codes="-5" android:keyEdgeFlags="right" android:isRepeatable="true"
android:keyIcon="@drawable/keyboard_delete_icon" />
</Row>
<Row>
<Key android:codes="52" android:keyLabel="4" />
<Key android:codes="53" android:keyLabel="5" />
<Key android:codes="54" android:keyLabel="6" />
</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:keyHeight=