【问题标题】:How do I clear the focus on an editext? Other StackOverflow posts haven't helped much如何清除编辑文本上的焦点?其他 Stack Overflow 帖子没有多大帮助
【发布时间】:2020-12-28 11:45:24
【问题描述】:

我查看了其他 StackOverflow 帖子,但其中许多都不起作用,或者 cmets 说它们不起作用。我想知道如何清除对编辑文本的关注。我希望当我关闭键盘时,它也会失去焦点,但这并没有发生。

因此,每当有人退出应用程序并返回 (应用程序在后台运行)时,常规键盘就会出现,即使它不应该出现。我有一个完整的系统来管理键盘。

显示/关闭键盘的代码

private void closeEmojiKeyboard()
    {
        ivEmoji.setVisibility(View.VISIBLE);
        ivKeyboard.setVisibility(View.GONE);
        showKeyboard(etMessage);
        llEmojiKeyboard.setVisibility(View.GONE);
    }

    private void showKeyboard(EditText view)
    {
        view.requestFocus();
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }

当有人打开表情符号键盘时隐藏键盘的代码

ivEmoji.setVisibility(View.GONE);
        ivKeyboard.setVisibility(View.VISIBLE);
        hideKeyboard(etMessage);
        llEmojiKeyboard.setVisibility(View.VISIBLE);

以及点击editext时隐藏表情键盘的代码

llEmojiKeyboard.setVisibility(View.GONE);
                showKeyboard(etMessage);
                ivEmoji.setVisibility(View.VISIBLE);
                ivKeyboard.setVisibility(View.GONE);
                rvMessages.scrollToPosition(messagesList.size()-1);

谁能与我分享一些代码,可以帮助我清晰地关注我的编辑文本?谢谢。

【问题讨论】:

    标签: android android-edittext focus


    【解决方案1】:

    你可以

    前 1.

     editText.clearFocus()
    

    前 2.

    EditText et = (EditText)view.findViewById(R.id.my_name);
     et.setInputType(EditorInfo.TYPE_NULL); // setCursorVisible(false);
    

    【讨论】:

      【解决方案2】:
      editText.setEnabled(false);
      editText.setFocusable(false);
      editText.setFocusableInTouchMode(false);
      editText.setCursorVisible(false);
      editText.setKeyListener(null);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-18
        • 2011-12-28
        • 2018-04-07
        相关资源
        最近更新 更多