问题描述
我正在 android 上实现自定义键盘.我刚刚阅读了有关developer.android.com"的文档并看到了带有软键盘的示例.我所能做的就是改变键盘背景,改变按钮的位置,将 keyicon 而不是 keylabel 设置为 key.
i am implementing custom keyboard on android. i have just read documentation on "developer.android.com" and seen sample with soft keyboard. all i can - it`s to change keyboard background, change placement of buttons, set keyicon instead of keylabel to key.
但是我还是不能改变key的背景和颜色.
but i still can not change key`s background and color.
请写一些 xml 或源代码的示例代码.谢谢!
please write some sample code of xml or source. thanks!
我更改背景的示例:
public class gbinput extends inputmethodservice implements keyboardview.onkeyboardactionlistener{ ... private gbkeyboardview minputview; @override public view oncreateinputview() { minputview = (gbkeyboardview) getlayoutinflater().inflate(r.layout.input, null); minputview.setonkeyboardactionlistener(this); minputview.setkeyboard(mqwertykeyboard); minputview.setbackgroundresource(r.color.keyboard_background); return minputview; } ... }
我需要这样的东西:
所有按钮的图像 - 这是个坏主意,所以我想找到更好的问题.
images for all buttons - its bad idea, so i want to find better issue.
推荐答案
将这行代码添加到你的 input.xml 中
add this line of code to your input.xml
android:keybackground="@drawable/samplekeybackground"
所以您的 input.xml 最终应该看起来与此类似.
so your input.xml should end up looking similar to this.
如果您已经有一个可以使用的drawable,否则这里有一个示例关键背景drawable,它将产生与您的示例图像类似的结果.
if you already have a drawable to use great otherwise here is a sample key background drawable that will produce results like your example image.
如果您想要 xml 中的所有内容,您可以使用 shape xml,如下所示.可绘制/normal.xml
if you want everything in xml you can use shape xml's like the following. drawable/normal.xml
和drawable/pressed.xml
and drawable/pressed.xml