Frage

I created a custom Input method by SoftKeyboard sample application. All I want is to have a background for the keys of the keyboard. I'm trying to make android:backgroundKey attribute working but it's not working.

I have an xml file like bellow:

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:keyHeight="10%p"
    android:verticalGap="0.50%p"
    android:horizontalGap="0.20%p"
android:keyBackground="@drawable/bg"
    >

    <Row android:keyHeight="6%p" android:keyWidth="7.50%p">
        <Key android:codes="49"    android:keyLabel="1" android:keyEdgeFlags="left" />
        <Key android:codes="50"     />
        <Key android:codes="51"    android:keyLabel="3" />
        <Key android:codes="52"    android:keyLabel="4" />
        <Key android:codes="53"    android:keyLabel="5" />
        <Key android:codes="54"    android:keyLabel="6" />
        <Key android:codes="55"    android:keyLabel="7" />
        <Key android:codes="56"    android:keyLabel="8" />
        <Key android:codes="57"    android:keyLabel="9" />
        <Key android:codes="48"    android:keyLabel="0" />
        <Key android:codes="45"    android:keyLabel="-" />
        <Key android:codes="42"    android:keyLabel="*" />
        <Key android:codes="-5"    android:keyIcon="@drawable/sym_keyboard_delete" 

    android:isRepeatable="true" /> 
    </Keyboard>
War es hilfreich?

Lösung

I figured out the problem. I was trying to add keyBackground attribute in key xml file. I had to use it in input.xml file. Here is the right place for using this attribute:

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

Andere Tipps

Add the attribute "android:keyBackground" to the xml file where you have declared the android.inputmethodservice.KeyboardView and it will work. Same goes for other key attributes like "android:keyTextColor".

<?xml version="1.0" encoding="utf-8"?>
<android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/keyboard_view"
    android:layout_alignParentBottom="true"
    android:keyPreviewLayout="@layout/keyboard_preview"
    android:keyBackground="@drawable/key_bg_border_white"
    android:keyTextColor="@color/colorAccent"
    android:background="@color/colorPrimary">
</android.inputmethodservice.KeyboardView>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top