This is a fairly simple question but I can't believe all answers I found were not working.
I have a layout with two EditText
and the bottom of the window is just some remaining blank space. I'd like each EditText
to loose focus when the user is clicking in the blank part of the window. So my guess is that I have to put something in the OnTouchListener
of the root View
:
rootView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Put something here
}
});
I have tried several things:
Requesting focus from the layout View
as suggested somewhere was in fact giving focus to one of the EditText
s.
I also tried setting setFocusable
for both EditText
s to false
but I was unable to put them back to true
afterwards.
I also tried the simple rootView.clearFocus()
, but it was also giving back the focus to one EditText
.
EDIT: My EditText
boxes are multilines so I can't use a 'Done' keyboard button since I need the return one to be present.
<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();
I use this when already finished update profile info and remove all focus from EditText in my layout
====> Update: In parent layout content my EditText add line:
android:focusableInTouchMode="true"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With