【问题标题】:How to set keyboard background in Android如何在Android中设置键盘背景
【发布时间】:2011-08-31 02:00:22
【问题描述】:

这听起来可能很愚蠢,但我确实是 Android 编程的新手。 我在互联网上查过这个,但似乎没有人遇到过这个问题。 我正在为我们学校的 Android 项目制作软键盘。 我打算为这个键盘制作自己的背景,但我不知道如何更改键盘的背景。 我在我的可绘制目录中创建了一个 buttonbgselector.xml 文件:

<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>

我尝试在这里设置背景:

@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;
}

而且钥匙还是一样的,没有任何改变。

【问题讨论】:

    标签: android keyboard background


    【解决方案1】:

    有一个名为 keyBackground 的 XML 属性。 只需将此属性设置为可绘制对象就可以了。

    将此属性添加到input.xml中的KeyboardView:

    <KeyboardView android:keyBackground="@drawable/buttonbgselector" .../>
    

    【讨论】:

    • 感谢您的回复,但遗憾的是,这并没有奏效。我想知道是不是我的 png 图片是原因
    • 非常感谢您的回答。
    猜你喜欢
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 2017-05-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多