我正在尝试更改单个密钥标签及其miniKeybord(popupKeyboard)资源ID其更改标签但是当我按下该密钥时其不更改miniKeyboard资源ID 我在候选视图中切换按钮,我想从中更改“。” “ - ”键入其更改的标签但不是longPress的ResourceID
这是我更改键标签和ResourceID的切换方法
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
this.editor = this.mSharedPreferences.edit();
switch (buttonView.getId()) {
case R.id.easyUrduToggleBtn:
if (isChecked) {
this.editor.putBoolean("easy_urdu", true);
this.mEasyUrdu = shouldChangePunctuationKey = true;
SoftKeyboard keyboard = (SoftKeyboard) mKeyboardSwitcher.getInputView().getKeyboard();
keyboard.mPunctuationKey.label = "۔";
keyboard.mPunctuationKey.codes = new int[]{keyboard.mPunctuationKey.label.charAt(0)};
keyboard.mPunctuationKey.popupResId = R.xml.popup_punctuation_ur;
mKeyboardSwitcher.getInputView().invalidateKey(keyboard.mPunctuationKey);
} else {
this.editor.putBoolean("easy_urdu", false);
this.mEasyUrdu = shouldChangePunctuationKey = false;
SoftKeyboard keyboard = (SoftKeyboard) mKeyboardSwitcher.getInputView().getKeyboard();
keyboard.mPunctuationKey.label = ".";
keyboard.mPunctuationKey.codes = new int[]{keyboard.mPunctuationKey.label.charAt(0)};
keyboard.mPunctuationKey.popupResId = R.xml.popup_punctuation;
mKeyboardSwitcher.getInputView().invalidateKey(keyboard.mPunctuationKey);
}
this.editor.apply();
return;
default:
return;
}
}
这是KeyboardBaseView
public void invalidateKey(Key key) {
if (key == null)
return;
mInvalidatedKey = key;
// TODO we should clean up this and record key's region to use in onBufferDraw.
mDirtyRect.union(key.x + getPaddingLeft(), key.y + getPaddingTop(),
key.x + key.width + getPaddingLeft(), key.y + key.height + getPaddingTop());
onBufferDraw();
invalidate(key.x + getPaddingLeft(), key.y + getPaddingTop(),
key.x + key.width + getPaddingLeft(), key.y + key.height + getPaddingTop());
}
它只是通过重绘它而不是miniKeyboardResource id来改变它的标签,当我长按其显示的旧miniKeyboard但是当我点击下一个EditText时它改变了资源ID,因为我在这个方法中检入了class SoftKeyboard extends Keyboard
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
XmlResourceParser parser) {
Key key = new LatinKey(res, parent, x, y, parser);
switch (key.getCode()) {
case 46:
mPunctuationKey=key;
if (LatinIME.shouldChangePunctuationKey) {
key.label = "۔";
key.codes = new int[]{key.label.charAt(0)};
key.popupResId=R.xml.popup_punctuation_ur;
mPunctuationKey=key;
Log.e("akjskjas",1+"");
} else {
key.label = ".";
key.codes = new int[]{key.label.charAt(0)};
key.popupResId=R.xml.popup_punctuation;
Log.e("akjskjas",2+"");
}
break;
但是从切换按钮不能正常工作它只更改标签而不是miniKeyboard key.popupResId
请帮我解决问题