Android 仿58同城自定义数字软键盘

这篇博客介绍如何在Android中创建一个自定义的数字软键盘,适用于数字录入场景,如输入手机号或支付键盘。通过设置键盘布局XML,自定义View进行绘制,并封装键盘功能,能方便地与EditText配合使用。
摘要由CSDN通过智能技术生成

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=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值