android定义键盘示例(斗地主或跑得快的记牌器)

 

今天突然想起以前斗地主的时候老记不住牌,于是乎想到做一个记牌器,为了方便记牌,需要自己定义一个android键盘,于是学习了一下利用android.inputmethodservice.Keyboard 来自己定义了一个软键盘效果如图所示:

在测试时发现预览框里面没有显示我们输入的内容,网上查找原因和浏览源代码都找不到解决方案,然后只好逐个测试,最后发现时程序默认主题覆盖使得提示框的字体颜色和背景颜色一致,把主题去掉或换一个主题即可解决

 还有当输入框为密码框时,需要加入edit.setTransformationMethod(PasswordTransformationMethod.getInstance());否则输入显示的是明文

 

具体实现:

keycontent.xml这个文件定义了键盘的布局

<?xml version="1.0" encoding="utf-8"?>  
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"  
    android:keyWidth="25%p"  
    android:horizontalGap="0px"  
    android:verticalGap="0px"  
    android:keyHeight="50dip">  
    <Row>  
        <Key android:codes="51" android:keyLabel="3" /> 
        <Key android:codes="52" android:keyLabel="4" />  
        <Key android:codes="53" android:keyLabel="5" />  
        <Key android:codes="54" android:keyLabel="6" /> 
       <!--  <Key android:codes="57419"  
            android:keyEdgeFlags="right"  
            android:keyIcon="@drawable/ic_launcher" />  --> 
    </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:codes="1010" android:keyLabel="10"
             android:keyEdgeFlags="right"  
             android:isRepeatable="true"   />
    </Row>  
    <Row>  
        <Key android:codes="74" android:keyLabel="J" />  
        <Key android:codes="81" android:keyLabel="Q" />  
        <Key android:codes="75" android:keyLabel="K" /> 
        <Key android:codes="65" android:keyLabel="A"
             android:keyEdgeFlags="right"  
             android:isRepeatable="true"   />
       
    </R
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值