6

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
user
  • 471
  • 2
  • 16
  • 31
  • What have you tried so far? Supplying code of what you have tried will help you get help. –  Aug 17 '13 at 07:16
  • i have set to input.xml and input1.xml – user Aug 17 '13 at 07:20
  • i need to get keycode at run time i.e different key color i have used three input.xml,input1.xml,input2.xml if input.xml inflate than keycolor will be green,blue combination if input1.xml inflate keys background color will red and orange ..similar for input2.xml so i am no getting how to this – user Aug 17 '13 at 07:26

1 Answers1

10

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! :)

Community
  • 1
  • 1
Yakov
  • 481
  • 5
  • 11