Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of keys in KeyboardView Class in custom Android keyboard? [duplicate]

I am working on a Custom Keyboard App. I need to set different themes for keys or background color in KeyboardView class and get key color at onCreateInputView() in SoftKeyboard extends InputMethodService Class.

However I am not getting how to get particular key according to keycode so I can change color or background of particular key.

like image 740
user Avatar asked Aug 17 '13 07:08

user


1 Answers

On any diffrent input layout use android:keyBackground=".."

example:

input.xml:

<com.example.KeyboardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/keyboard"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:keyBackground="@drawable/blue_key"
        />

input1.xml:

<com.example.KeyboardView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/keyboard"
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:keyBackground="@drawable/red_key"
            />

then on OnCreateInputView method:

@Override public View onCreateInputView() {
    if(theme == 1)
        mInputView = (KeyboardView) getLayoutInflater().inflate(R.xml.input , null);
    else
        mInputView = (KeyboardView) getLayoutInflater().inflate(R.xml.input1 , null);
    mInputView.setOnKeyboardActionListener( this);
    mInputView.setKeyboard(mQwertyKeyboard);
    mComposing.setLength(0);
    return mInputView;
}

and on the end of the method onStartInput add this:

setInputView(onCreateInputView());

If you've already done it and what you need is to set a different background to special keys. Maybe the solution to my problem that I wrote will help you: https://stackoverflow.com/a/18354298/2683898

Good Luck! :)

like image 86
Yakov Avatar answered Oct 23 '22 01:10

Yakov