按照此示例 https://android.googlesource.com/platform/development/+/master/samples/SoftKeyboard/ ,我有我自己的軟鍵盤。 我想修改KEYCODE_ENTER行爲。Android自定義軟鍵盤 - 更改KEYCODE_ENTER行爲以跳過非默認軟鍵盤行爲的非EditText對象
例子:我有活性的,其佈局layout_A: 的EditText edt_1 +複選框chb_1 +的EditText edt_2
的Android默認的軟鍵盤的行爲:
focus edt_1 > KEYCODE_ENTER > skip chb_1 > focus edt_2 >> what I want
我的軟鍵盤:
focus edt_1 > KEYCODE_ENTER > focus chb_1 >> FAIL
任何一個有Android默認軟鍵盤的源代碼? (與數字文本鍵盤和全文鍵盤佈局)
任何建議可能會有所幫助,非常感謝你。
public class SoftKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener
@Override public void onStartInput(EditorInfo attribute, boolean restarting) {
super.onStartInput(attribute, restarting);
// Reset our state. We want to do this even if restarting, because
// the underlying state of the text editor could have changed in any way.
mComposing.setLength(0);
updateCandidates();
if (!restarting) {
// Clear shift states.
mMetaState = 0;
}
boolean isEditText = true;
mPredictionOn = false;
mCompletionOn = false;
mCompletions = null;
//TODO: setup own behavior
// We are now going to initialize our state based on the type of
// text being edited.
switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
case InputType.TYPE_CLASS_NUMBER:
mCurKeyboard = mNumberKeyboard;
break;
case InputType.TYPE_CLASS_DATETIME:
// Numbers and dates default to the symbols keyboard, with
// no extra features.
mCurKeyboard = mSymbolsKeyboard;
break;
case InputType.TYPE_CLASS_PHONE:
// Phones will also default to the symbols keyboard, though
// often you will want to have a dedicated phone keyboard.
mCurKeyboard = mSymbolsKeyboard;
break;
case InputType.TYPE_CLASS_TEXT:
// This is general text editing. We will default to the
// normal alphabetic keyboard, and assume that we should
// be doing predictive text (showing candidates as the
// user types).
mCurKeyboard = mQwertyKeyboard;
mPredictionOn = true;
// We now look for a few special variations of text that will
// modify our behavior.
int variation = attribute.inputType & InputType.TYPE_MASK_VARIATION;
if (variation == InputType.TYPE_TEXT_VARIATION_PASSWORD ||
variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
// Do not display predictions/what the user is typing
// when they are entering a password.
mPredictionOn = false;
}
if (variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|| variation == InputType.TYPE_TEXT_VARIATION_URI
|| variation == InputType.TYPE_TEXT_VARIATION_FILTER) {
// Our predictions are not useful for e-mail addresses
// or URIs.
mPredictionOn = false;
}
if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) {
// If this is an auto-complete text view, then our predictions
// will not be shown and instead we will allow the editor
// to supply their own. We only show the editor's
// candidates when in fullscreen mode, otherwise relying
// own it displaying its own UI.
mPredictionOn = false;
mCompletionOn = isFullscreenMode();
}
// We also want to look at the current state of the editor
// to decide whether our alphabetic keyboard should start out
// shifted.
updateShiftKeyState(attribute);
break;
default:
// For all unknown input types, default to the alphabetic
// keyboard with no special features.
mCurKeyboard = mNonEditTextKeyboard;
updateShiftKeyState(attribute);
isEditText = false;
}
// Update the label on the enter key, depending on what the application
// says it will do.
mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions);
if ((mInputView!= null) && (!isEditText)) {
//TODO: handle non edit text case.
handleClose();
}
}
這不是他要求的... – 2015-10-13 15:45:31
感謝您的解決方案,但我正在使用鍵盤服務,它不綁定到特定的活動。我不知道Android如何默認軟鍵盤工作?它如何跳過非編輯文本對象並將焦點集中到下一個編輯文本? –
默認情況下應該這樣做。哪個視圖會去?或者它只是崩潰? – vguzzi