我正在尝试学习android键盘api。
使用softKeyboard示例,我正在尝试更改密钥图标,我可以更改所有内容,但图标永远不会更改。
我在使用此行的onLongPress方法的LatinKeyboardView中进行此操作:
copia.icon = getResources().getDrawable(R.drawable.tecladir);
但图标不会改变。
即使使用
this.invalidateAllKeys();
要强制重绘键,图标仍然保持不变。
onLongPress的完整代码如下:
@Override
protected boolean onLongPress(Key key) {
key.icon = getResources().getDrawable(R.drawable.tecladir);
//tecladir is one image i have
key.text = "batata";
key.label = "batata";
this.invalidateAllKeys();
//default code of method
if (key.codes[0] == Keyboard.KEYCODE_CANCEL) {
getOnKeyboardActionListener().onKey(KEYCODE_OPTIONS, null);
return true;
} else {
return super.onLongPress(key);
}
}
我错过了什么吗?
答案 0 :(得分:0)
好的,找到了解决方案。
在分配新图标之前,标签必须为空,否则图标不会改变,正确的方法是:
key.label = null;
key.icon = getResources().getDrawable(R.drawable.tecladir);