android 9 啟動(dòng)登錄界面編輯框有焦點(diǎn)無彈出全鍵盤

問題描述

啟動(dòng)登錄界面編輯框有焦點(diǎn)無彈出全鍵盤

問題分析

通過dumpsys input_methodke可以看到當(dāng)前編輯框確實(shí)是有焦點(diǎn)的症副。

查看代碼

    override fun onResume() {
        super.onResume()
        if (mEditText?.requestFocus() == true) {
            val imm = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.showSoftInput(mEditText, InputMethodManager.SHOW_FORCED)
        }
    }

在onResume時(shí)requestFocus如果拿到焦點(diǎn),獲取彈出全鍵盤革娄。

 <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:windowSoftInputMode="stateVisible|adjustResize"
            android:theme="@style/Theme.MalsDemo.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

在AndroidMainfest.xml中也有聲明android:windowSoftInputMode ,可就是彈不出來。

看log。

把input相關(guān)的log都打開(這個(gè)打開需要源碼支持趣苏。)

2022-04-08 11:21:39.260 4369-4369/com.android.launcher3 V/InputMethodManager: focusOut: view=com.android.launcher3.allapps.AllAppsRecyclerView{41d7cd9 VFED..... .F...... 0,32-1920,1080 #7f0a0016 app:id/apps_list_view},focus=true,windowFocus=false,autofillUiShowing=false,window=android.view.ViewRootImpl$W@bc40603,temporaryDetach=false mServedView=com.android.launcher3.allapps.AllAppsRecyclerView{41d7cd9 VFED..... .F...... 0,32-1920,1080 #7f0a0016 app:id/apps_list_view},focus=true,windowFocus=false,autofillUiShowing=false,window=android.view.ViewRootImpl$W@bc40603,temporaryDetach=false
2022-04-08 11:21:39.265 2071-2087/system_process D/InputMethodManagerService: --- calledFromForegroundUserOrSystemProcess ? calling uid = 10032 system uid = 1000 calling userId = 0, foreground user id = 0, calling pid = 12420com.android.server.InputMethodManagerService.showSoftInput(InputMethodManagerService.java:2585)
2022-04-08 11:21:39.265 2071-2087/system_process W/InputMethodManagerService: Ignoring showSoftInput of uid 10032: com.android.internal.view.IInputMethodClient$Stub$Proxy@b46356
2022-04-08 11:21:39.289 12420-12420/com.example.teamsdemo V/InputMethodManager: focusIn: androidx.appcompat.widget.AppCompatEditText{381cff VFED..CL. .F..H.ID 0,303-1920,363 #7f0801c8 app:id/textview_first},focus=true,windowFocus=true,autofillUiShowing=false,window=android.view.ViewRootImpl$W@f44b072,temporaryDetach=false
2022-04-08 11:21:39.292 12420-12420/com.example.teamsdemo V/InputMethodManager: onWindowFocus: androidx.appcompat.widget.AppCompatEditText{381cff VFED..CL. .F..H.ID 0,303-1920,363 #7f0801c8 app:id/textview_first} softInputMode=STATE_ALWAYS_VISIBLE|ADJUST_RESIZE|IS_FORWARD_NAVIGATION first=true flags=#81810100
2022-04-08 11:21:39.292 12420-12420/com.example.teamsdemo V/InputMethodManager: Restarting due to mRestartOnNextWindowFocus
2022-04-08 11:21:39.293 12420-12420/com.example.teamsdemo V/InputMethodManager: focusIn: androidx.appcompat.widget.AppCompatEditText{381cff VFED..CL. .F..H.ID 0,303-1920,363 #7f0801c8 app:id/textview_first},focus=true,windowFocus=true,autofillUiShowing=false,window=android.view.ViewRootImpl$W@f44b072,temporaryDetach=false
2022-04-08 11:21:39.293 12420-12420/com.example.teamsdemo V/InputMethodManager: checkFocus: view=androidx.appcompat.widget.AppCompatEditText{381cff VFED..CL. .F..H.ID 0,303-1920,363 #7f0801c8 app:id/textview_first} next=androidx.appcompat.widget.AppCompatEditText{381cff VFED..CL. .F..H.ID 0,303-1920,363 #7f0801c8 app:id/textview_first} forceNewFocus=true package=com.example.teamsdemo
2022-04-08 11:21:39.293 12420-12420/com.example.teamsdemo V/InputMethodManager: Starting input: view=androidx.appcompat.widget.AppCompatEditText{381cff VFED..CL. .F..H.ID 0,303-1920,363 #7f0801c8 app:id/textview_first},focus=true,windowFocus=true,autofillUiShowing=false,window=android.view.ViewRootImpl$W@f44b072,temporaryDetach=false reason=WINDOW_FOCUS_GAIN
2022-04-08 11:21:39.300 12420-12420/com.example.teamsdemo V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@e0d4fd2 ic=androidx.emoji2.viewsintegration.EmojiInputConnection@86928a3
2022-04-08 11:21:39.300 12420-12420/com.example.teamsdemo V/InputMethodManager: START INPUT: view=androidx.appcompat.widget.AppCompatEditText{381cff VFED..CL. .F..H.ID 0,303-1920,363 #7f0801c8 app:id/textview_first},focus=true,windowFocus=true,autofillUiShowing=false,window=android.view.ViewRootImpl$W@f44b072,temporaryDetach=false ic=androidx.emoji2.viewsintegration.EmojiInputConnection@86928a3 tba=android.view.inputmethod.EditorInfo@e0d4fd2 controlFlags=#107
2022-04-08 11:21:39.302 2071-3080/system_process D/InputMethodManagerService: --- calledFromForegroundUserOrSystemProcess ? calling uid = 10032 system uid = 1000 calling userId = 0, foreground user id = 0, calling pid = 12420com.android.server.InputMethodManagerService.startInputOrWindowGainedFocus(InputMethodManagerService.java:2754)
2022-04-08 11:21:39.302 2071-3080/system_process V/InputMethodManagerService: windowGainedFocus: reason=WINDOW_FOCUS_GAIN client=android.os.BinderProxy@497f086 inputContext=com.android.internal.view.IInputContext$Stub$Proxy@d96afd7 missingMethods= attribute=android.view.inputmethod.EditorInfo@a0690c4 controlFlags=#107 softInputMode=STATE_ALWAYS_VISIBLE|ADJUST_RESIZE|IS_FORWARD_NAVIGATION windowFlags=#81810100 unverifiedTargetSdkVersion=32
2022-04-08 11:21:39.302 2071-3080/system_process V/InputMethodManagerService: Window asks to always show input
2022-04-08 11:21:39.302 2071-3080/system_process V/InputMethodManagerService: unbindCurrentInputLocked: client=android.os.BinderProxy@38c5d29
2022-04-08 11:21:39.302 2071-3080/system_process V/InputMethodManagerService: Hide switching menu
2022-04-08 11:21:39.302 2071-3080/system_process V/InputMethodManagerService: switching to client: client=android.os.BinderProxy@497f086 keyguard=false
2022-04-08 11:21:39.303 4369-4369/com.android.launcher3 I/InputMethodManager: handleMessage: MSG_SET_ACTIVE false, was true
2022-04-08 11:21:39.303 2071-3080/system_process V/InputMethodManagerService: Disabling: SessionState{uid 10009 pid 4369 method 897a721 session 4e829fb channel ClientState{411b9e3 uid 10009 pid 4369} (server)}
2022-04-08 11:21:39.303 2071-3080/system_process V/InputMethodManagerService: Enabling: SessionState{uid 10032 pid 12420 method 897a721 session e838736 channel ClientState{28cee6a uid 10032 pid 12420} (server)}
2022-04-08 11:21:39.303 4369-4369/com.android.launcher3 I/InputMethodManager: handleMessage: MSG_UNBIND 60 reason=SWITCH_CLIENT
2022-04-08 11:21:39.303 4369-4369/com.android.launcher3 V/InputMethodManager: Clearing binding!
2022-04-08 11:21:39.303 2071-3080/system_process D/InputMethodManagerService: showCurrentInputLocked: mCurToken=android.os.Binder@14f2b7b
2022-04-08 11:21:39.303 2071-3080/system_process V/InputMethodManagerService: Calling com.android.internal.view.IInputMethod$Stub$Proxy@897a721.showSoftInput(0, null)
2022-04-08 11:21:39.303 4714-4714/com.test.tvime V/InputMethodService: unbindInput(): binding=InputBinding{android.os.BinderProxy@86e0336 / uid 10009 / pid 4369} ic=InputConnectionWrapper{idHash=#7b6430e mMissingMethods=}
2022-04-08 11:21:39.306 4714-4714/com.test.tvime V/InputMethodService: bindInput(): binding=InputBinding{android.os.BinderProxy@cd0033c / uid 10032 / pid 12420} ic=InputConnectionWrapper{idHash=#1f5d8c5 mMissingMethods=}
2022-04-08 11:21:39.307 2071-2087/system_process D/InputMethodManagerService: --- calledFromForegroundUserOrSystemProcess ? calling uid = 10007 system uid = 1000 calling userId = 0, foreground user id = 0, calling pid = 4714com.android.server.InputMethodManagerService.reportFullscreenMode(InputMethodManagerService.java:4616)
2022-04-08 11:21:39.314 4714-4714/com.test.tvime V/InputMethodService: startInput(): editor=android.view.inputmethod.EditorInfo@b17821a
2022-04-08 11:21:39.314 12420-12420/com.example.teamsdemo V/InputMethodManager: Starting input: Bind result=InputBindResult{result=SUCCESS_WITH_IME_SESSION method=com.android.internal.view.IInputMethodSession$Stub$Proxy@3a27a0 id=com.test.tvime/com.test.ime.softkeyboard.IME sequence=61 userActionNotificationSequenceNumber=3}
2022-04-08 11:21:39.316 4714-4714/com.test.tvime V/InputMethodService: CALL: onFinishInput
2022-04-08 11:21:39.316 4714-4714/com.test.tvime V/InputMethodService: CALL: onStartInput
2022-04-08 11:21:39.316 4714-4714/com.test.tvime V/InputMethodService: showSoftInput()
2022-04-08 11:21:39.316 4714-4714/com.test.tvime V/InputMethodService: clearInsetOfPreviousIme()  mShouldClearInsetOfPreviousIme=false
2022-04-08 11:21:39.339 12420-12420/com.example.teamsdemo I/InputMethodManager: handleMessage: MSG_SET_ACTIVE true, was false
2022-04-08 11:21:39.757 4369-4369/com.android.launcher3 V/InputMethodManager: onViewDetachedFromWindow: view=android.view.View{436647f V.ED..... ......ID 385,70-473,158},focus=false,windowFocus=false,autofillUiShowing=false,window=android.view.ViewRootImpl$W@bc40603,temporaryDetach=false mServedView=com.android.launcher3.allapps.AllAppsRecyclerView{41d7cd9 VFED..... .F....ID 0,32-1920,1080 #7f0a0016 app:id/apps_list_view},focus=true,windowFocus=false,autofillUiShowing=false,window=android.view.ViewRootImpl$W@bc40603,temporaryDetach=false

這邊關(guān)鍵的log在這里,都走到InputMethodService的showSoftInput梯轻,還沒顯示全鍵盤食磕。

2022-04-08 11:21:39.316 4714-4714/com.test.tvime V/InputMethodService: showSoftInput()

看源碼

//InputMethodService#showSoftInput ,傳入?yún)?shù)(0,null)

public void showSoftInput(int flags, ResultReceiver resultReceiver) {
            if (DEBUG) Log.v(TAG, "showSoftInput()");
            boolean wasVis = isInputViewShown();
            if (dispatchOnShowInputRequested(flags, false)) {
                try {
                    showWindow(true);
                } catch (BadTokenException e) {
                    // We have ignored BadTokenException here since Jelly Bean MR-2 (API Level 18).
                    // We could ignore BadTokenException in InputMethodService#showWindow() instead,
                    // but it may break assumptions for those who override #showWindow() that we can
                    // detect errors in #showWindow() by checking BadTokenException.
                    // TODO: Investigate its feasibility.  Update JavaDoc of #showWindow() of
                    // whether it's OK to override #showWindow() or not.
                }
            }
            clearInsetOfPreviousIme();
            // If user uses hard keyboard, IME button should always be shown.
            mImm.setImeWindowStatus(mToken, mStartInputToken,
                    mapToImeWindowStatus(isInputViewShown()), mBackDisposition);
            if (resultReceiver != null) {
                resultReceiver.send(wasVis != isInputViewShown()
                        ? InputMethodManager.RESULT_SHOWN
                        : (wasVis ? InputMethodManager.RESULT_UNCHANGED_SHOWN
                                : InputMethodManager.RESULT_UNCHANGED_HIDDEN), null);
            }
        }

//InputMethodService#dispatchOnShowInputRequested ,傳入?yún)?shù)(0喳挑,false)

private boolean dispatchOnShowInputRequested(int flags, boolean configChange) {
    final boolean result = onShowInputRequested(flags, configChange);
    if (result) {
        mShowInputFlags = flags;
    } else {
        mShowInputFlags = 0;
    }
    return result;
}

//InputMethodService#onShowInputRequested ,傳入?yún)?shù)(0彬伦,false)

public boolean onShowInputRequested(int flags, boolean configChange) {
    if (!onEvaluateInputViewShown()) {
        return false;
    }
    if ((flags&InputMethod.SHOW_EXPLICIT) == 0) {//true
        if (!configChange && onEvaluateFullscreenMode()) {true && false
            // Don't show if this is not explicitly requested by the user and
            // the input method is fullscreen.  That would be too disruptive.
            // However, we skip this change for a config change, since if
            // the IME is already shown we do want to go into fullscreen
            // mode at this point.
            return false;
        }
        if (!mSettingsObserver.shouldShowImeWithHardKeyboard() && //true && true
                getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS) {
            // And if the device has a hard keyboard, even if it is
            // currently hidden, don't show the input method implicitly.
            // These kinds of devices don't need it that much.
            return false;
        }
    }
    return true;
}

//InputMethodService#onEvaluateInputViewShown

public boolean onEvaluateInputViewShown() {
    if (mSettingsObserver == null) {
        Log.w(TAG, "onEvaluateInputViewShown: mSettingsObserver must not be null here.");
        return false;
    }
    if (mSettingsObserver.shouldShowImeWithHardKeyboard()) {
        return true;
    }
    Configuration config = getResources().getConfiguration();
    return config.keyboard == Configuration.KEYBOARD_NOKEYS
            || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES;
}

SettingsObserver#shouldShowImeWithHardKeyboard()

private boolean shouldShowImeWithHardKeyboard() {
    // Lazily initialize as needed.
    if (mShowImeWithHardKeyboard == ShowImeWithHardKeyboardType.UNKNOWN) {
        mShowImeWithHardKeyboard = Settings.Secure.getInt(mService.getContentResolver(),
                Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0) != 0 ?
                ShowImeWithHardKeyboardType.TRUE : ShowImeWithHardKeyboardType.FALSE;
    }
    switch (mShowImeWithHardKeyboard) {
        case ShowImeWithHardKeyboardType.TRUE:
            return true;
        case ShowImeWithHardKeyboardType.FALSE:
            return false;
        default:
            Log.e(TAG, "Unexpected mShowImeWithHardKeyboard=" + mShowImeWithHardKeyboard);
            return false;
    }
}

這邊輸入 settings get secure show_ime_with_hard_keyboard 獲取到的值是0
所以shouldShowImeWithHardKeyboard 返回false。導(dǎo)致沒有執(zhí)行到showWindow(),從而沒有顯示輸入框.

猜測(cè)

settings put secure show_ime_with_hard_keyboard 1 把這個(gè)值設(shè)置為1伊诵,驗(yàn)證是否可行单绑。
從這邊看,如果shouldShowImeWithHardKeyboard返回false曹宴,還會(huì)判斷

config.keyboard == Configuration.KEYBOARD_NOKEYS
            || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES

如果這邊條件為true搂橙,也是可以走到下一個(gè)流程的〉烟梗可以代碼測(cè)試一下這個(gè)條件是否為真区转,我這邊驗(yàn)證時(shí)可以的。

config.keyboard == Configuration.KEYBOARD_NOKEYS // false
config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES //true

修改

這邊涉及到設(shè)備環(huán)境問題了弯屈。
如果設(shè)備沒有按鍵蜗帜,那config.keyboard == Configuration.KEYBOARD_NOKEYS應(yīng)該是true
如果設(shè)備有按鍵的時(shí)候允許彈全鍵盤,那settings secure show_ime_with_hard_keyboard 這個(gè)值不應(yīng)該設(shè)置為0.
所以是我們?cè)O(shè)備的系統(tǒng)配置有問題资厉。改上面的任一個(gè)條件都可。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末蔬顾,一起剝皮案震驚了整個(gè)濱河市宴偿,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌诀豁,老刑警劉巖窄刘,帶你破解...
    沈念sama閱讀 218,941評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異舷胜,居然都是意外死亡娩践,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,397評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來翻伺,“玉大人材泄,你說我怎么就攤上這事《至耄” “怎么了拉宗?”我有些...
    開封第一講書人閱讀 165,345評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)辣辫。 經(jīng)常有香客問我旦事,道長(zhǎng),這世上最難降的妖魔是什么急灭? 我笑而不...
    開封第一講書人閱讀 58,851評(píng)論 1 295
  • 正文 為了忘掉前任姐浮,我火速辦了婚禮,結(jié)果婚禮上葬馋,老公的妹妹穿的比我還像新娘单料。我一直安慰自己,他們只是感情好点楼,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,868評(píng)論 6 392
  • 文/花漫 我一把揭開白布扫尖。 她就那樣靜靜地躺著,像睡著了一般掠廓。 火紅的嫁衣襯著肌膚如雪换怖。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,688評(píng)論 1 305
  • 那天蟀瞧,我揣著相機(jī)與錄音沉颂,去河邊找鬼。 笑死悦污,一個(gè)胖子當(dāng)著我的面吹牛铸屉,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播切端,決...
    沈念sama閱讀 40,414評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼彻坛,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了踏枣?” 一聲冷哼從身側(cè)響起昌屉,我...
    開封第一講書人閱讀 39,319評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎茵瀑,沒想到半個(gè)月后间驮,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,775評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡马昨,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評(píng)論 3 336
  • 正文 我和宋清朗相戀三年竞帽,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了扛施。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,096評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡屹篓,死狀恐怖疙渣,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情抱虐,我是刑警寧澤昌阿,帶...
    沈念sama閱讀 35,789評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站恳邀,受9級(jí)特大地震影響懦冰,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜谣沸,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,437評(píng)論 3 331
  • 文/蒙蒙 一刷钢、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧乳附,春花似錦内地、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,993評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至举农,卻和暖如春荆针,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背颁糟。 一陣腳步聲響...
    開封第一講書人閱讀 33,107評(píng)論 1 271
  • 我被黑心中介騙來泰國(guó)打工航背, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人棱貌。 一個(gè)月前我還...
    沈念sama閱讀 48,308評(píng)論 3 372
  • 正文 我出身青樓玖媚,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親婚脱。 傳聞我的和親對(duì)象是個(gè)殘疾皇子今魔,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,037評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容