I have a customized keyboard which uses images to represent the keys. I'm currently having a problem with the key sizes, as the images have a set size. After I set the keyIcon
, there are blank spaces on the side since the keyWidth
that was set does not match the image. Here is what it looks like: http://s4.postimg.org/kyvpi86kd/Screenshot_2013_05_01_10_12_06.png
This is the code that I use to setup my keyboard within my application:
KeyboardView keyboardView = (KeyboardView)view.findViewById(R.id.keyboardView);
Keyboard keyboard = new Keyboard(getActivity(), R.xml.key_pin_pad);
Where R.xml.key_pin_pad
is the xml file used to populate the keyboard.
Is there a way to emulates LinearLayouts for keyboard xmls? I would really like to be able to do something like layout_width="wrap_content"
instead of manipulating the pixel width to see if the keys fit.
Edit:
I was able to make the keys fit in place by setting the key backgrounds in the XML of the KeyboardView:
<android.inputmethodservice.KeyboardView
...
android:keyBackground="@drawable/keypad_1"/>
If there is no keyIcon
set, then the image fits exactly as I'd like for it to. Unfortunately, every one of my keys has its own drawable, so this is setting the background of every key to "1". Does anyone know of a way to generalize the setting of the backgrounds? Manually setting the keyBackground
of the keys of R.xml.key_pin_pad
show nothing for some reason.
After looking at this further, I have decided that the simplest method here is to just change the icon images.
Instead of having key icons consisting of a number/background, The icons will just be numbers with transparent backgrounds and a separate, number-less background drawable will be used in place of the KeyboardView
keyBackground
.