Android平板设备上的数字小键盘自定义控件的实现(非弹出软键盘)

       最近公司项目需要在输入信息界面上设置自定义数字小键盘,使用非android系统自带键盘来输入。

且有多个界面需要该键盘,因此将其写成自定义控件以便复用。
先来个效果图:
接下来开始一步步实现这个小键盘了!
首先上布局,布局也就是自定义控件的布局,将来要在代码中引用过去的,效果如上图,由16个Button组成,
本人比较喜欢线性布局,因此一律用线性布局完成,因人而异,相对也可。设置按钮背景selector(这个是效果,按需求来)。
 
  
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
 
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
 
<Button
android:id="@+id/bt_keyboard_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/keyboard_keybg_selector"
android:text="1"
android:textColor="#fff"
android:textSize="40sp" />
 
<Button
android:id="@+id/bt_keyboard_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:background="@drawable/keyboard_keybg_selector"
android:text="2"
android:textColor="#fff"
android:textSize="40sp" />
 
<Button
android:id="@+id/bt_keyboard_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:background="@drawable/keyboard_keybg_selector"
android:text="3"
android:textColor="#fff"
android:textSize="40sp" />
 
<Button
android:id="@+id/bt_keyboard_abc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:background="@drawable/keyboard_keybg_selector"
android:text="abc"
android:textColor="#fff"
android:textSize="40sp" />
</LinearLayout>
 
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal" >
 
<Button
android:id="@+id/bt_keyboard_4"
android:layout_width=
  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值