问题
I'm using the following code (this is a part of it) for my softKeyboard.
<Row android:rowEdgeFlags="bottom" >
<Key
android:codes="83"
android:keyLabel="CLR" />
<Key
android:codes="39"
android:keyLabel="0" />
<Key
android:codes="42"
style="@style/deleteKeyboard"
android:keyIcon="@drawable/button_delete"
android:isRepeatable="true"
android:keyLabel="DEL" />
</Row>
For some reason style or keyIcon won't work. Not matter what, I can't set only one button on keyboard to different layout. What am I doing wrong? I tried just with style and keyIcon, but no combination worked so far.
<style name="deleteKeyboard">
<item name="android:keyTextColor">#EEEEEE</item>
<item name="android:keyBackground">@drawable/button_delete</item>
<item name="android:keyTextSize">15sp</item>
</style>
回答1:
As it turns out, keyIcon cannot be combined with android:keyLabel. This is the only way I could solve that.
<Row android:rowEdgeFlags="bottom" >
<Key
android:keyIcon="@drawable/clear_numeric"
android:codes="83"/>
<Key
android:codes="39"
android:keyLabel="0" />
<Key
android:codes="42"
android:keyIcon="@drawable/delete_numeric"
android:isRepeatable="true"/>
</Row>
delete_numeric and clear_numeric are just transparent PNGs (see below) with CLR and DEL on it. To change background of those I had to use android:background="@drawable/numeric_background"
inside <android.inputmethodservice.KeyboardView />
. This is a PNG with background and colored patches below those buttons (you also need to make button background half transparent!). Size of the image does not matter, as it will stretch.
- numeric_background.png
- clear_numeric.png and delete_numeric.png
来源:https://stackoverflow.com/questions/16895396/keyicon-doesnt-work