首页 > 解决方案 > 为 kiosk 应用程序永久响应本机 android 隐藏或禁用键盘

问题描述

我需要在我的信息亭模式应用程序中禁用或隐藏键盘。我用谷歌搜索它并没有找到隐藏整个应用程序的键盘而不失去输入焦点的方法(因为我将使用外部键盘)。

我还希望能够通过单击按钮或其他东西来显示键盘以进行维护。

有谁能在这里帮助我吗?

标签: androidreact-nativekeyboardshow-hidedismiss

解决方案


在您的活动下的清单文件中使用:

<activity ... android:windowSoftInputMode="stateHidden">

然后在您的 oncreate 事件中创建一个 ontouchlistener :

MyEdittext.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View MyView, MotionEvent event) {
    MyView.onTouchEvent(event);
    InputMethodManager inputMethod = (InputMethodManager)MyView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethod!= null) {
        inputMethod.hideSoftInputFromWindow(MyView.getWindowToken(), 0);
    }                
    return true;
}

});

要重新启用键盘,只需将其添加到要启用的 xml 项目中:

android:textIsSelectable="true"

希望有帮助..


推荐阅读