我正在为我的软键盘使用以下代码(这是其中的一部分)。
<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>
由于某种原因,style 或 keyIcon 无法工作。无论如何,我不能只将键盘上的一个按钮设置为不同的布局。我究竟做错了什么?我只尝试了 style 和 keyIcon,但到目前为止还没有任何组合有效。
<style name="deleteKeyboard">
<item name="android:keyTextColor">#EEEEEE</item>
<item name="android:keyBackground">@drawable/button_delete</item>
<item name="android:keyTextSize">15sp</item>
</style>
最佳答案
事实证明,keyIcon 不能与 android:keyLabel 结合使用。这是我解决这个问题的唯一方法。
<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 和clear_numeric 只是透明的PNG(见下文),上面有CLR 和DEL。要更改那些我必须使用 android:background="@drawable/numeric_background"
的背景里面<android.inputmethodservice.KeyboardView />
。这是一个带有背景和这些按钮下方的彩色补丁的 PNG(您还需要使按钮背景半透明!)。图像的大小并不重要,因为它会拉伸(stretch)。
- numeric_background.png
- clear_numeric.png 和delete_numeric.png
关于android - 按键图标不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16895396/