SoftKeyboard does not allow keyOutputText and keyIcon on same Key
I am trying to modify the SoftKeyboard
example (Andriod 3.1 on Moto Xoom) so that I can use an icon on the key and have it output a unicode
character when that key is pressed.
unicode \u266B
. Unfortunately I cannot use keyOutputText
and keyIcon
on the same key in the symbols.xml
file which lays out the keys. I need keyIcon
because I could not find a way to change the Typeface
on the Keyboard Keys
to one with that character. I found where I would do it, but its a call to a private method (.setTypeFace)
buried in android.jar
(KeyboardView
if I recall) so I can't.
So I just use an icon to put on the key. This works fine in combination with android:codes
, however android:codes
will not output my unicode
character when I feed it android:codes="\\u266B"
which documentation says it should accept.
android:keyOutputText="\u266B"
to get the character to actually output into my EditText
. So I can make the key display an icon of my character and the EditText
display the character itself, but not the two together. When I try to use the 2 together it compiles and runs just fine, then I hit the shift button on the keyboard to display the symbols and only the numbers 0-9 show up, the rest of the keyboard is just gone. Now error messages or anything, just gone. Nowher开发者_JAVA技巧e does it say these two things are exclusive that I could find, nor does it make any logical sense for them to be. If this is a bug, I just want to know so I can accept it and stop banging my head against it (a planned fix date would be nice too). If not, how can I get both the key on the keyboard
and the EditText
box to show my beamed eighth note. I am open to any suggestion or work arounds. Thanks.
Use a HashMap to map the android:codes to your unicode character.
In XML :
<Key android:codes="719" android:keyIcon="@drawable/zo"/> //use your icon and required code here
In java code:
HashMap<String, String> keyCodeMap = new HashMap<String, String>();
keyCodeMap.put("719", ""+'\u0986');
Then, in the onKey(int primaryCode, int[] keyCodes)
method get the corresponding character using using following code:
String c = keyCodeMap.get(String.valueOf(primaryCode));
Use the value of c where you need.
Not sure if this is really going to help, since it's for AnySoftKeyboard
, but the problem is the same, so maybe the solution is too?
What solved the problem (for me, creating a layout for ASK) was this:
supply both keyIcon
and keyOutputText
AS WELL as android:codes
, but NO keyLabel
!
keyLabel
gets filled (by ASK?) with the first letter of android:codes, but you still see the image and it outputs multi-letter text.
Hope it helps, might be worth a try in any case, I guess.
(Please note: I just found this out and although I could reproduce it, I can't guarantee if it really was this that solved the problem. I honestly think so, though.)
Instead of using \u266B
in android:codes
try the int value of the unicode: 0x266B
.
Then from onKey
you can convert it back to String using:
Character.toString((char)primaryCode)
精彩评论