Android从所有视图中删除焦点

wiz*_*mer 8 android focus android-edittext

这是一个相当简单的问题,但我不相信我发现的所有答案都不起作用.

我有两个布局,EditText窗口底部只剩下一些空白区域.EditText当用户点击窗口的空白部分时,我希望每个人都失去焦点.所以我的猜测是我必须OnTouchListener在根中添加一些内容View:

rootView.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
            // Put something here
    }
});
Run Code Online (Sandbox Code Playgroud)

我尝试了几件事:

  • View某个地方建议的布局请求焦点实际上是关注其中一个EditText.

  • 我也试过设置setFocusable两个EditTexts false但我无法将它们放回去true.

  • 我也尝试过简单rootView.clearFocus(),但它也把重点放在一个EditText.

编辑:我的EditText盒子是多线的,所以我不能使用'完成'键盘按钮,因为我需要返回一个存在.

Ho *_*ong 5

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/ll_root_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical">

LinearLayout llRootView = findViewBindId(R.id.ll_root_view);
llRootView.clearFocus();
Run Code Online (Sandbox Code Playgroud)

我已经完成更新配置文件信息并从布局中的EditText移走所有焦点时使用它

====>更新:在父布局内​​容中,我的EditText添加行:

android:focusableInTouchMode="true"
Run Code Online (Sandbox Code Playgroud)