Thought
Thought

Reputation: 5856

Keyboard key label not changing color on press

I have this keyboard in one of the layouts of my app

<android.inputmethodservice.KeyboardView
        android:id="@+id/keyboard_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_centerHorizontal="true"
        android:focusable="true"
        android:clickable="true"
        android:background="@color/lightBlue"
        android:shadowColor="@android:color/transparent"
        android:keyBackground="@drawable/list_item_selector"
        android:keyTextColor="@color/drawer_text_color_selector"
        android:focusableInTouchMode="true"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" />

it all works ok except the color selection of the text inside the keys. When i press it i want it to change colors. In case of the background it changes correctly , but the text stays the same color

this is the xml i use for the text color

    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:state_pressed="false" android:color="@color/bodyTextSelectedColor"/>
    <item android:state_focused="true" android:state_pressed="true" android:color="@color/bodyTextSelectedColor"/>
    <item android:state_focused="false" android:state_pressed="true" android:color="@color/bodyTextSelectedColor"/>
    <item android:state_checked="true" android:color="@color/bodyTextSelectedColor"/>
    <item android:color="@color/bodyTextColor"/>
</selector>

where bodyTextSelectedColor is white and bodyTextColor is black should i change something in my KeyboardView or my selector?

Upvotes: 2

Views: 315

Answers (1)

Blanc
Blanc

Reputation: 175

KeyBoardView does not support selectors for the textColor, at least not officially.

In the documentation for KeyboardView, android:keyBackground mentions selectors while the entry for keyTextcolor simply states:

Color to use for the label in a key.

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

Further evidence is that your syntax seems correct and applying it to the keyBackground changes the background as expected.

Upvotes: 2

Related Questions