android自定义数字软键盘、修改review按钮的样式

Android提供KeyboardView可以让用户实现对软键盘的自定义;具体的定义数字键盘,还是字符键盘可以按照自己的需求进行定制;

本文提供数字键盘的自定义实现,并解决软键盘按下后review背景按钮样式的修改;

(1)main.xml文件下面定义一个KeyboardView;

(2)在xml文件夹下面定义一个数字键盘number.xml文件;

(3)提供一个软件盘的实现工具类

先上运行后的效果图,不是你要的就不用仔细读代码啦



main.xml中的核心代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.lyy.input.MainActivity" >
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="31dp"
        android:ems="10"
        android:inputType="number" >
    </EditText>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <android.inputmethodservice.KeyboardView
            android:id="@+id/keyboard_view"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#F4F4F4"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:keyBackground="@drawable/btn_keyboard_key"
            android:keyPreviewLayout="@layout/key_preview_layout"
            android:shadowColor="#FFFFFF"
            android:shadowRadius="0.0"
            android:keyTextColor="#000000" />
    </RelativeLayout>
</RelativeLayout>


number.xml中的代码如下;主要用来定义数字键;注意该文件存放在xml文件夹下面;

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:horizontalGap="3dp"
    android:keyHeight="48dp"
    android:keyWidth="33.33%p"
    android:verticalGap="3dp" >

    <Row>
        <Key
            android:codes="49"
            android:keyLabel="1" />
        <Key
            android:codes="50"
            android:keyLabel="2" />
        <Key
            android:codes="51"
            andr

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值