如何设置不同的背景在XML键盘上的功能键? [英] How to set a different background for function key in xml on keyboard?
问题描述
我为Android开发一个键盘应用程序。我试着设置不同的背景正常键和功能键,但是它没有工作:
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android>
&所述;! - 功能键。 - >
<项目安卓state_single =真正的机器人:STATE_ pressed =真
机器人:可绘制=@可绘制/ btn_keyboard_special/>
<项目安卓state_single =真
机器人:可绘制=@可绘制/ btn_keyboard_special/>
&所述;! - 切换键。使用可检查/检验状态。 - >
<项目安卓state_checkable =真正的机器人:state_checked =真正的机器人:STATE_ pressed =真
机器人:可绘制=@可绘制/ btn_keyboard_key_dark_ pressed_on/>
<项目安卓state_checkable =真正的机器人:STATE_ pressed =真
机器人:可绘制=@可绘制/ btn_keyboard_key_dark_ pressed_off/>
<项目安卓state_checkable =真正的机器人:state_checked =真
机器人:可绘制=@可绘制/ btn_keyboard_key_dark_normal_on/>
<项目安卓state_checkable =真
机器人:可绘制=@可绘制/ btn_keyboard_key_dark_normal_off/>
<! - 普通钥匙 - >
<项目的android:STATE_ pressed =真
机器人:可绘制=@可绘制/发光/>
<项目机器人:可绘制=@可绘制/ btn_keyboard_key_light_normal/>
< /选择器>
有一个XML属性名为Android:keyBackground。只需将该属性设置为一个绘制,它应该是好的。
将此attrbute到KeyboardView在input.xml中:
< KeyboardView安卓keyBackground =@可绘制/ buttonbgselector... />
我使用的是何种分配的背景颜色为所有的按键假设这是。
有关单独的功能键,建立一个适当的前景绘制的图像,以覆盖整个关键,它的键盘布局XML的XML分配给 keyIcon
。
要做到完美,使用覆盖相同尺寸也,柜面你不想改变keyIcon背景图像
I am developing a keyboard application for Android. I tried to set different background for normal key and function key but it didn't work:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Functional keys. -->
<item android:state_single="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_special" />
<item android:state_single="true"
android:drawable="@drawable/btn_keyboard_special" />
<!-- Toggle keys. Use checkable/checked state. -->
<item android:state_checkable="true" android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_dark_pressed_on" />
<item android:state_checkable="true" android:state_pressed="true"
android:drawable="@drawable/btn_keyboard_key_dark_pressed_off" />
<item android:state_checkable="true" android:state_checked="true"
android:drawable="@drawable/btn_keyboard_key_dark_normal_on" />
<item android:state_checkable="true"
android:drawable="@drawable/btn_keyboard_key_dark_normal_off" />
<!-- Normal keys -->
<item android:state_pressed="true"
android:drawable="@drawable/glow" />
<item android:drawable="@drawable/btn_keyboard_key_light_normal" />
</selector>
There is a XML-Attribute called android:keyBackground. Just set this attribute to a drawable and it should be fine.
Add this attrbute to the KeyboardView in input.xml:
<KeyboardView android:keyBackground="@drawable/buttonbgselector" .../>
I'm assuming this is what you are using to assign background color for all the keys.
For the function keys alone, create a proper foreground drawable image to cover the entire key and assign it to keyIcon
in the xml of the keyboard layout xml.
To be perfect, use a background image that covers the same dimension also, incase you don't want to change the keyIcon
这篇关于如何设置不同的背景在XML键盘上的功能键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!