android enthusiast
android enthusiast

Reputation: 2092

How to change the colour of a key text in a custom keyboard?

I've writing a simple input method editor and I'm a bit stuck on changing the colour of the actual Key. Here is my keyboardView which is located in res/layout:

<?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="wrap_content"
    android:id="@+id/keyboard"
    android:keyBackground="@drawable/key_background"
    android:keyPreviewLayout="@layout/preview">

</android.inputmethodservice.KeyboardView>

my key_background:

<item
    android:state_focused="false"
    android:state_selected="false"
    android:state_pressed="false"
    android:drawable="@drawable/normal"
    />

<item

    android:state_pressed="true"
    android:drawable="@drawable/pressed"
    />

, the normal state

<item android:bottom="2dp">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/white"/>
    </shape>
</item>

and the pressed state

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/keyboard_pressed"/>

</shape>

So I am stuck changing the colour of the actual symbols (ie a, b, c etc) to black. Please see attached screen shot with what I got so far. enter image description here

Thank you in advance.

Upvotes: 3

Views: 1922

Answers (1)

Kilarn123
Kilarn123

Reputation: 733

From KeyboardView Doc :

android:keyTextColor

You can add this attribute to your KeyboardView

Color to use for the label in a key.

May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

Upvotes: 2

Related Questions