0

I'm trying to make my custom keyboard to change his colors according to the current theme in project, but it fails, this is my code:

<?xml version="1.0" encoding="UTF-8"?>
    <android.inputmethodservice.KeyboardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/keyboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:keyBackground = "@drawable/keybackground"
        android:keyTextColor="?attr/colorPrimary"
        android:background="?attr/android:colorBackground"
        android:keyTextSize="22sp"/>

When I put regular colors everything works fine! How can I do it flexible?

halfer
  • 19,824
  • 17
  • 99
  • 186
batsheva
  • 2,175
  • 1
  • 20
  • 32
  • Possible duplicate of [How to set different background of keys for Android Custom Keyboard](https://stackoverflow.com/questions/18224520/how-to-set-different-background-of-keys-for-android-custom-keyboard) – Nouman Ch Oct 30 '17 at 11:44
  • no my qoustion is completely different! please read before marking it as duplicate... – batsheva Oct 30 '17 at 11:49

1 Answers1

0

I'm not sure this is what you are looking for but you could try using the res-auto namespace:

<android.inputmethodservice.KeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:id="@+id/keyboard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    custom:keyBackground = "@drawable/keybackground"
    custom:keyTextColor="?attr/colorPrimary"
    android:background="?attr/android:colorBackground"
    custom:keyTextSize="22sp"/>

If you are looking for changing it dynamically while the app is running I think the linked answer is the way to go. Things that should be changed dynamically is preferably done in code while static design preferably is done in xml.

Warpzit
  • 27,966
  • 19
  • 103
  • 155