Android 输入法如何获取EditText的inputTyp

2019-11-24  本文已影响0人  败家的猫

inputType属性的作用在于给输入法足够的上下文
Properly set the {@link android.R.attr#inputType} in your editable
text views, so that the input method will have enough context to help the
user in entering text into them.

android.widget.TextView.java
public TextView(
Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
if (mEditor != null) {
//实际是mEditor
mEditor.adjustInputType(password, passwordInputType, webPasswordInputType,
numberPasswordInputType);
}
}

android.widget.Editor.java
Helper class used by TextView to handle editable text views.

InputContentType mInputContentType;

静态内部类
static class InputContentType {
int imeOptions = EditorInfo.IME_NULL;
String privateImeOptions;
CharSequence imeActionLabel;
int imeActionId;
Bundle extras;
OnEditorActionListener onEditorActionListener;
boolean enterDown;
LocaleList imeHintLocales;
}

android.view.inputmethod.EditorInfo.java
public class EditorInfo implements InputType, Parcelable {

/**
 * The content type of the text box, whose bits are defined by
 * {@link InputType}.
 *
 * @see InputType
 * @see #TYPE_MASK_CLASS
 * @see #TYPE_MASK_VARIATION
 * @see #TYPE_MASK_FLAGS
 */
public int inputType = TYPE_NULL;

}

android.text.InputType.java

/**

/**

/**

/**

android.inputmethodservice.InputMethodService.java

/**

/**

void doStartInput(InputConnection ic, EditorInfo attribute, boolean restarting) {
if (!restarting) {
doFinishInput();
}
mInputStarted = true;
mStartedInputConnection = ic;
mInputEditorInfo = attribute;
initialize();
if (DEBUG) Log.v(TAG, "CALL: onStartInput");
onStartInput(attribute, restarting);
if (mWindowVisible) {
if (mShowInputRequested) {
if (DEBUG) Log.v(TAG, "CALL: onStartInputView");
mInputViewStarted = true;
onStartInputView(mInputEditorInfo, restarting);
startExtractingText(true);
} else if (mCandidatesVisibility == View.VISIBLE) {
if (DEBUG) Log.v(TAG, "CALL: onStartCandidatesView");
mCandidatesViewStarted = true;
onStartCandidatesView(mInputEditorInfo, restarting);
}
}
}

/**

上一篇下一篇

猜你喜欢

热点阅读