Android 自定义键盘整理

本文介绍了两种在Android中实现自定义键盘的方法。方式一是手动绘制UI并处理事件,适用于简单数字键盘。方式二是利用系统提供的KeyboardView,通过XML配置键盘布局,适合功能丰富的键盘。文章还提供了相关代码示例和注意事项。
摘要由CSDN通过智能技术生成

前一段时间,由于业务需要,了解了一下关于自定义键盘的相关操作。

实现方式

主要是两种实现方式,我这里就以一个数字键盘来作为实现。
方式一效果图
方式一
方式二效果图
方式二

方式一

该方式是使用我们最原始的方式,自己画UI ,然后去实现监听事件,
这种方式我们就不过多废话,先来看一下自己画的 xml ,

<?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:background="@color/white"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_60"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/kb_tv_1"
            style="@style/keyboard_text_style"
            android:text="1" />

        <View style="@style/keyboard_ver_line" />

        <TextView
            android:id="@+id/kb_tv_2"
            style="@style/keyboard_text_style"
            android:text="2" />

        <View style="@style/keyboard_ver_line" />

        <TextView
            android:id="@+id/kb_tv_3"
            style="@style/keyboard_text_style"
            android:text="3" />

    </LinearLayout>

    <View style="@style/keyboard_hor_line" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_60"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/kb_tv_4"
            style="@style/keyboard_text_style"
            android:text="4" />

        <View style="@style/keyboard_ver_line" />

        <TextView
            android:id="@+id/kb_tv_5"
            style="@style/keyboard_text_style"
            android:text="5" />

        <View style="@style/keyboard_ver_line" />

        <TextView
            android:id="@+id/kb_tv_6"
            style="@style/keyboard_text_style"
            android:text="6" />

    </LinearLayout>

    <View style="@style/keyboard_hor_line" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_60"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/kb_tv_7"
            style="@style/keyboard_text_style"
            android:text="7" />

        <View style="@style/keyboard_ver_line" />

        <TextView
            android:id="@+id/kb_tv_8"
            style=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值