How to set background on Android keyboard

This may sound silly, but I'm seriously new to Android programming. I looked it up on the Internet, but it seems like there has never been a problem with it. I am making a soft keyboard for our school Android project. I intended to make my own background for this keyboard, but I could not figure out how to change the background on the keyboard. I made the buttonbgselector.xml file in my accessible directory:

<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 the same, nothing has changed.

+5
source share
1 answer

XML-, keyBackground. drawable, .

attrbute KeyboardView input.xml:

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

All Articles