Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set keyboard background in Android

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.

like image 783
hoangbv15 Avatar asked May 23 '11 11:05

hoangbv15


People also ask

Can I change the color of my keyboard on my phone?

Android phones don't require third-party apps, as they already allow you to change keyboard color. However, iPhone users can use third-party apps to create a similar effect. Here's how to do so using Gboard, Google's keyboard app. Install the Gboard app from the App Store.

How do I make my keyboard letters darker?

Customize your keyboard with a custom theme Open the app > tap Set Keyboard Theme > select a color option from the options, including red, blue, green, pink, black or gray options.


1 Answers

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

Add this attrbute to the KeyboardView in input.xml:

<KeyboardView android:keyBackground="@drawable/buttonbgselector" .../>
like image 86
Franziskus Karsunke Avatar answered Sep 29 '22 10:09

Franziskus Karsunke