在输入焦点上隐藏android键盘

时间:2016-07-12 09:19:49

标签: android

我有一个隐藏在视图中的输入,是否有办法在关注输入时停止显示键盘的Android设备?

3 个答案:

答案 0 :(得分:2)

如果您只想在androi设备上禁用焦点,则必须检测用户代理。您可以使用https://github.com/rafaelp/css_browser_selector。此插件将用户代理添加到您的html标记



$('.android input').on('focus', function (e) {
   $(this).blur(); 
  e.preventDefault(); 
 
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text"/>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

docker run功能中。

onCreate

您也可以从清单文件中执行此操作。在this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 标记内。

<activity>

答案 2 :(得分:0)

public static void hideSoftKeyboard(Activity activity) {
    if (activity.getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }
}

public static void hideSoftKeyboard(Fragment fragment) {
    if (fragment.getActivity().getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) fragment.getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(fragment.getActivity().getCurrentFocus().getWindowToken(), 0);
    }
}