如何在Android中设置键盘背景 [英] How to set keyboard background in Android

查看:55
本文介绍了如何在Android中设置键盘背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来可能很愚蠢,但我确实是 Android 编程的新手.我在互联网上查过这个,但似乎没有人遇到过这个问题.我正在为我们学校的 Android 项目制作软键盘.我打算为这个键盘制作自己的背景,但我不知道如何更改键盘的背景.我在我的可绘制目录中创建了一个 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-Attribute 叫 keyBackground.只需将此属性设置为可绘制对象就可以了.

There is a XML-Attribute called keyBackground. Just set this attribute to a drawable and it should be fine.

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

Add this attrbute to the KeyboardView in input.xml:

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

这篇关于如何在Android中设置键盘背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆