我擴展了InputMethodService,希望使用此服務來顯示軟鍵盤,即使連接了硬鍵盤(基於以下帖子Show soft keyboard even though a hardware keyboard is connected)。有沒有辦法在應用程序內綁定到這個服務,而不必在清單中聲明它?最終結果是使InputMethodService.onEvaluateInputViewShown返回true,這樣即使連接了硬鍵盤,軟鍵盤也會顯示。使用輸入法服務的子類
我想用擴展的類MultiInputMethodService在顯示/ hideSoftKeyboard的inputmethodmanager:
public class MultiInputMethodService extends InputMethodService {
@Override
public boolean onEvaluateInputViewShown() {
Log.i("onEvaluateInputViewShow","onEvaluateInputViewShown");
return true;
}
}
我的活動:
private void showSoftKeyboard() {
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
}
private void hideSoftKeyboard() {
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.myInput.getEditText().getWindowToken(), 0);
}