Reputation: 2295
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?
Upvotes: 0
Views: 214
Reputation: 28162
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.
Upvotes: 0