【问题标题】:Hide softkeyboard for locker app隐藏储物柜应用程序的软键盘
【发布时间】:2015-06-29 22:41:09
【问题描述】:

我正在尝试关闭在另一个应用程序中打开的软键盘。 我从这里尝试了所有解决方案: Programmatically Hide/Show Android Soft Keyboard 或这里:Close/hide the Android Soft Keyboard

正如您在图片中看到的那样,我必须关闭从另一个应用程序打开的键盘,添加到清单以不使键盘可见并没有成功。

要注意这是一个储物柜应用程序,我会在手机进入睡眠模式时启动一项活动。

我错过了什么吗?从商店测试其他储物柜应用程序并没有遇到这个问题

但结果如下:

编辑:更多信息

这就是我启动储物柜的方式:

if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
    //Toast.makeText(context, "" + "screeen off", Toast.LENGTH_SHORT).show();

    wasScreenOn = false;
    Intent intent = new Intent(context, LockScreenActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    context.startActivity(intent);

    // do whatever you need to do here
    //wasScreenOn = false;
} 

这是清单代码:

<activity
    android:name=".ui.activities.LockScreenActivity"
    android:excludeFromRecents="true"
    android:noHistory="true"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

【问题讨论】:

    标签: android android-softkeyboard


    【解决方案1】:

    我终于解决了这个问题。这是我的活动清单代码的样子:

    <activity
            android:name=".ui.activities.LockScreenActivity"
            android:excludeFromRecents="true"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden"
            android:configChanges="keyboardHidden"
            android:launchMode="singleInstance"
            android:multiprocess="false"
            android:stateNotNeeded="true"
            android:taskAffinity=""
            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
    

    【讨论】:

    • 我试过这个但没有效果。请让我知道是否需要做其他事情,除了这个
    • @AkarshM 我也没有为我工作,它只在某些设备上工作,遗憾的是,该项目被搁置,所以我没有做更多的研究
    【解决方案2】:

    试试这个方法

      InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    

    Check this link

    【讨论】:

    • 我的视图中没有任何编辑文本。编辑文本位于另一个独立于我的应用的应用中
    • 你好,请检查我编辑的答案,添加一个有用的链接希望它对你有帮助
    【解决方案3】:

    可以实现覆盖此活动的onPause(),并使用以下代码作为

    @Override
    public void onPause() {
        super.onPause();
        if (null != getWindow()){
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        }
    }
    

    【讨论】:

    • 不隐藏软键盘
    【解决方案4】:

    在你的活动中试试这个:

    private void hideKeyboard() {   
        // Check if no view has focus:
        View view = this.getCurrentFocus();
        if (view != null) {
            InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
    

    【讨论】:

    【解决方案5】:

    尝试替换 android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"android:windowSoftInputMode="stateHidden" 输入 AndroidManifest.xml这样的

    <activity
            android:name=".ui.activities.LockScreenActivity"
            android:excludeFromRecents="true"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
    

    参考可以参考http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

    "stateHidden" 软键盘在用户选择时隐藏 活动——也就是说,当用户肯定地向前导航到 活动,而不是因为离开另一个活动而退缩 活动。

    "stateAlwaysHidden" 软键盘总是隐藏 活动的主窗口具有输入焦点。

    【讨论】:

    • 同样的问题 :( ...如果我从短信作曲家或谷歌搜索打开键盘,键盘不会隐藏。在类似 whatsapp 的应用程序中尝试过,但它也适用于我的解决方案 :(
    猜你喜欢
    • 2011-09-01
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-17
    • 2015-11-30
    • 1970-01-01
    相关资源
    最近更新 更多