android 自定义键盘的安全性,自定义安全键盘——仿民生银行

本文介绍了为何需要自定义Android键盘,主要是出于安全性考虑,例如在输入敏感信息时防止键盘窃取数据。详细展示了如何创建自定义键盘布局,包括键的XML属性、KeyboardView属性,以及如何实现不同键的按下效果。此外,还提供了一个自定义EditText子类,用于处理键盘输入逻辑和切换。最后讨论了开发中遇到的问题,如预览框大小设置和键盘遮挡问题。
摘要由CSDN通过智能技术生成

系统自带键盘和第三方的键盘不管是从性能还是从体验上来说都要胜于我们自己写的,但我们为什么还要去自定义键盘呢?其实就为了安全性,比如用户在输入账户密码,支付密码的时候,防止键盘获取到我们的数据;或者说美工要求Android的键盘需要和IOS的一样,那我们就得自己去写个键盘了。

效果图:

9212ecc3a1b9

keyboardView.gif

一:键盘布局

XML布局属性

9212ecc3a1b9

Keyboard.Key的属性.png

9212ecc3a1b9

KeyboardView的属性.png

9212ecc3a1b9

Keyboard.Row的属性.png

9212ecc3a1b9

ASCII值.png

Key和Row为Keyboard的静态内部类,从上面的图中我们能看到每个属性对应的Description,在这里再简单介绍一下。

Key的xml属性

属性说明

android:codes

表示键Key的标签,字母/符号/数字对应的ASCII值。

android:iconPreview

表示键点击后放大后的View

android:isModifier

按键是否为功能键,例如Alt/Shift/Ctrl键。取值为true或false。

android:isRepeatable

表示长时间按下key键重复执行这个键的操作,如:长按删除键会一直执行删除操作。

android:isSticky

指定按键是否为状态键。如:Shift大小写切换按键,具有两种状态,按下状态和正常状态,取值为true或则false。

android:keyEdgeFlags

指定按键的对齐指令,取值为left或则right。

android:keyIcon

按键图标,如果指定了该值则文本属性无效。

android:keyLabel

代表按键显示的文本内容。

android:keyOutputText

指定按键输出的文本内容,取值为字符串。

android:popupCharacters

表示编辑特殊字符,空格、换行等.。

android:popupKeyboard

表示按键点击预览窗口。

android:horizontalGap

键的水平间隙,当前键的左边的水平间隙。

KeyboardView的xml属性

属性说明

android:background

设置整个键盘的背景色

android:keyPreviewHeight

正在输入时弹出预览框的高度

android:keyPreviewLayout

输入时预览框的布局样式,要求根布局为TextView。

android:keyTextColor

键的字体颜色

android:keyTextSize

键的字体大小

android:labelTextSize

字符串键文本字体大小

android:shadowColor、android:shadowRadius

设置这两个属性可以很好的解决键的字体发虚的问题,设置shadowColor值和键的字体颜色相同。

android:keyBackground

设置键的背景色,可以用drawable中的selector标签设置键的正常状态样式和按下样式

英文键盘

android:horizontalGap="0.0px"

android:keyHeight="7.5%p"

android:keyWidth="8%p"

android:verticalGap="0.0px">

android:codes="113"

android:horizontalGap="1%p"

android:keyEdgeFlags="left"

android:keyLabel="q"

android:keyWidth="8%p"/>

android:codes="119"

android:horizontalGap="2%p"

android:keyLabel="w"

android:keyWidth="8%p"/>

android:codes="101"

android:horizontalGap="2%p"

android:keyLabel="e"

android:keyWidth="8%p"/>

android:codes="114"

android:horizontalGap="2%p"

android:keyLabel="r"

android:keyWidth="8%p"/>

android:codes="116"

android:horizontalGap="2%p"

android:keyLabel="t"

android:keyWidth="8%p"/>

android:codes="121"

android:horizontalGap="2%p"

android:keyLabel="y"

android:keyWidth="8%p"/>

android:codes="117"

android:horizontalGap="2%p"

android:keyLabel="u"

android:keyWidth="8%p"/>

android:codes="105"

android:horizontalGap="2%p"

android:keyLabel="i"

android:keyWidth="8%p"/>

android:codes="111"

android:horizontalGap="2%p"

android:keyLabel="o"

android:keyWidth="8%p"/>

android:codes="112"

android:horizontalGap="2%p"

android:keyEdgeFlags="right"

android:keyLabel="p"

android:keyWidth="8%p"/>

android:codes="97"

android:horizontalGap="6%p"

android:keyEdgeFlags="left"

android:keyLabel="a"

android:keyWidth="8%p"/>

android:codes="115"

android:horizontalGap="2%p"

android:keyLabel="s"

android:keyWidth="8%p"/>

android:codes="100"

android:horizontalGap="2%p"

android:keyLabel="d"

android:keyWidth="8%p"/>

android:codes="102"

android:horizontalGap="2%p"

android:keyLabel="f"

android:keyWidth="8%p"/>

android:codes="103"

android:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值