如何设置键盘背景的Android [英] How to set keyboard background in Android
问题描述
这听起来很蠢,但我是认真的新手,在Android的编程。 我已经看过这个在互联网上,但它看起来像没有人这个曾经有过的困难。 我想提出一个软键盘为我们学校的Android项目。 我打算让我自己的背景,这个键盘,但我无法弄清楚如何改变键盘的背景。 我在绘制DIR做出了buttonbgselector.xml文件:
This might sound stupid, but I'm seriously a newbie at Android programming. I have looked this up on the Internet, but it looks like nobody ever had difficulties with this. I am making a soft keyboard for our school Android project. I intended to make my own background for this keyboard, but I couldn't figure out how to change the keyboard's background. I made a buttonbgselector.xml file in my drawable dir:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/button" />
<item
android:state_pressed="true"
android:drawable="@drawable/buttonpressed" />
<item
android:state_checkable="true"
android:drawable="@drawable/button" />
<item
android:state_checkable="true"
android:state_pressed="true"
android:drawable="@drawable/buttonpressed" />
<item
android:state_checkable="true"
android:state_checked="true"
android:drawable="@drawable/button" />
<item
android:state_checkable="true"
android:state_checked="true"
android:state_pressed="true"
android:drawable="@drawable/buttonpressed" />
</selector>
我试图在这里设置背景:
I tried setting the background here:
@Override public View onCreateInputView() {
mInputView = (KeyboardView) getLayoutInflater().inflate(
R.layout.input, null);
mInputView.setBackgroundResource(R.drawable.buttonbgselector);
mInputView.setOnKeyboardActionListener(this);
mInputView.setKeyboard(mQwertyKeyboard);
return mInputView;
}
和按键都还是一样的,没有什么改变。
And the keys are still the same, nothing changed.
推荐答案
有一个XML属性名为<一个href="http://developer.android.com/reference/android/inputmethodservice/KeyboardView.html#attr_android%3akeyBackground">keyBackground. 只需将该属性设置为一个绘制,它应该是好的。
There is a XML-Attribute called keyBackground. Just set this attribute to a drawable and it should be fine.
将此attrbute到KeyboardView中的 input.xml中的:
Add this attrbute to the KeyboardView in input.xml:
<KeyboardView android:keyBackground="@drawable/buttonbgselector" .../>
这篇关于如何设置键盘背景的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!