49_自定义键盘基础知识及xml属性配置

Android基础汇总

效果图

 

 

 

 

 

ss

 

说明:因篇幅原因,本文只讲API和一些属性,后面的文字,会有相应的Demo和代码分析

 

#1 KeyboardView
 
1 结构
java.lang.Object
↳ android.view.View
↳ android.inputmethodservice.KeyboardView
 
2 class overview类描述
一个视图,它显示虚拟键盘。它处理呈现的键和检测按键和触摸动作。
 
3 总结:
1)嵌套的类:KeyboardView.OnKeyboardActionListener ,用于虚拟键盘事件的侦听器
2)XML Attributes
android:keyBackground 键盘按钮的背景 ,建议用drawable类型选择器,显示选中与未选中效果
android:keyPreviewLayout 按钮按下时反馈的布局视图
android:keyPreviewOffset 反馈视图的垂直偏移,必须是dimension类型的值
android:keyTextColor 按钮文字的颜色
android:keyTextSize 按钮中字符的大小
android:labelTextSize 没有图片的按钮中文本大小
android:popupLayout 布局资源弹出键盘
android:verticalCorrection 抵消触摸Y坐标,偏差纠正
 
#2 Keyboard
1.结构
extends Object
java.lang.Object
↳ android.inputmethodservice.Keyboard
2 class overview类描述
加载的XML描述键盘和存储的属性键。一个键盘(Keyboard)由成排(Row)的钥匙(Key)组成。
键盘的布局文件为XML格式,如:
<Keyboard
android:keyWidth="%10p"
android:keyHeight="50px"
android:horizontalGap="2px"
android:verticalGap="2px" >
<Row android:keyWidth="32px" >
<Key android:keyLabel="A" />
...
</Row>
...
</Keyboard>
后缀为%是相对于基准的高度或者宽度,而%p则是相对于“父亲”的宽度或高度百分比
3 总结:
1)嵌套的类:
class Keyboard.Key 按钮,类用于描述一个键的位置和特征的键盘.
class Keyboard.Row 列,键在键盘的容器
2)XML Attributes
android:horizontalGap 每个Key之间默认的水平间距
android:keyHeight Key的默认高度.
android:keyWidth Key的默认宽度..
android:verticalGap 每行(Row)之间的默认行间距
 
#3 Keyboard.Row
1 结构
java.lang.Object
↳ android.inputmethodservice.Keyboard.Row
2 class overview类描述
键(Key)在键盘的容器。所有键连续在同一(Y)坐标。一些关键尺寸每行可以覆盖默认的键盘(Keyboard)定义。
3 总结:
1)XML Attributes
android:horizontalGap 每个Key之间的默认间距.
android:keyHeight Key的默认高度
android:keyWidth Key的默认宽度
android:keyboardMode keyboard的模式(Mode)
android:rowEdgeFlags 边境标记
android:verticalGap 垂直Key之间的差距.
 
#4 Keyboard.Key
1 结构
java.lang.Object
↳ android.inputmethodservice.Keyboard.Key
2 class overview类描述
类用于描述一个键的位置和特征的键盘(按钮)
3 总结:
1)XML Attributes
android:codes (这个关键的unicode值或逗号分隔值输出)The unicode value or comma-separated values that this key outputs.
android:horizontalGap key之间的水平距离
android:iconPreview 预览中显示的图片
android:isModifier (是否这是一个修改器关键如Alt或转变)Whether this is a modifier key such as Alt or Shift.
android:isRepeatable (是否long-pressing这个键会重复)Whether long-pressing on this key will make it repeat.
android:isSticky 是否这是一个切换键
android:keyEdgeFlags 边界标记
android:keyHeight 高度
android:keyIcon 代替label的图片
android:keyLabel 显示在按钮上的内容.
android:keyOutputText 按这个键时,输出字符的字符串
android:keyWidth 宽度
android:popupCharacters 字符显示在弹出键盘
android:popupKeyboard XML任何弹出键盘的键盘布局
 
Demo:
<!-- this is the row that shows in both modes -->
<Row android:keyWidth="51dp">
<Key android:codes="49" android:keyLabel="1" />
<Key android:codes="50" android:keyLabel="2" />
<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="55" android:keyLabel="7" />
<Key android:codes="56" android:keyLabel="8" />
<Key android:codes="57" android:keyLabel="9" />
<Key android:codes="48" android:keyLabel="0"/>
</Row>

 

#5 Key Code 对应表
1 数字
字符: 0 1 2 3 4 5 6 7 8 9
code: 48 49 50 51 52 53 54 55 56 57
2 字母
大小写可以用一套,通过java的API来修改得到的字符
字符: q w r t y u i 7 o p
code: 113 119 101 114 116 121 117 105 111 112
字符: a s d f g h j k l
code: 97 115 100 102 103 104 106 107 108
字符: z x c v b n m
code: 122 120 99 118 98 110 109
 
3 特殊符号
字符: 空格 .
code: 32 46
 
4 自定义
code 设置为负数,在代码中解析,如
<Key android:keyWidth="20.000004%p"
android:codes="-3"
android:keyEdgeFlags="right"
android:keyLabel="完成" />
解析:
public void onKey(int primaryCode, int[] keyCodes) {
switch (primaryCode) {
case -3:
//监听到了code为-3按钮按下
break;
...
}
}
...
 
 
 
 

#6 实现

http://blog.csdn.net/baopengjian/article/details/70224530
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值