Android 仿「微信」自定义数字键盘

本文介绍了如何在Android中实现一个仿微信的自定义数字键盘,包括XML布局设计、点击事件处理以及与EditText的结合使用,通过反射禁用系统软键盘,提供了一种简单但实用的键盘解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最终效果:

实现这个自定义键盘的思路很简单:
1. 要写出一个数字键盘的布局;
2. 与 Edittext 结合使用,对每个按键的点击事件进行处理;
3. 禁用系统软键盘。

有了思路,实现起来就不难了。

1. 实现键盘的 xml 布局

网格样式的布局用 GridView 或者 RecyclerView 都可以实现,其实用 GridView 更方便一些,不过我为了多熟悉 RecyclerView 的用法,这里选择用了 RecyclerView。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="2px"
        android:background="@color/btn_gray"/>

    <RelativeLayout
        android:id="@+id/rl_back"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/iv_back_bg"
        android:padding="10dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@mipmap/keyboard_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值