androidandroid-custom-keyboard

Change Key Icon from a Java File for a custom keyboard


I got a code to change key label from my java file by

keyboard.getKeys().get(0).label= "@";

I want to change my key icon as well. But it fails.

keyboard.getKeys().get(9).icon= R.Drawable.myicon;

an error shows when I do like that saying that is int value. I don't how to make this possible in other way.

Any Help?


Solution

  • Yes, you need drawable for icon as in

    keyboard.getKeys().get(9).icon = ContextCompat.getDrawable(Context, R.drawable.myicon);