In my application I have a single EditText
together with some TextViews
, button and a spinner. My EditText receives focus since it is the only focu
For me this worked
Add these attributes to your EditText
android:focusable="true"
android:focusableInTouchMode="true"
After this in your code you can simply write
editText.clearFocus()
You just have to clear the focus from the view as
EditText.clearFocus()
Use the attached code to give the focus to "someone else", this is OK if you have a view where you simply want to dismiss the keyboard and release the focus, you don't really care about who gets it.
Use like this: FocusHelper.releaseFocus(viewToReleaseFocusFrom)
public class FocusHelper {
public static void releaseFocus(View view) {
ViewParent parent = view.getParent();
ViewGroup group = null;
View child = null;
while (parent != null) {
if (parent instanceof ViewGroup) {
group = (ViewGroup) parent;
for (int i = 0; i < group.getChildCount(); i++) {
child = group.getChildAt(i);
if(child != view && child.isFocusable())
child.requestFocus();
}
}
parent = parent.getParent();
}
}
}
Doc: The method traverses from the child view and up the view tree and looks for the first child to give focus to.
Edit: You can also use the API for this:
View focusableView = v.focusSearch(View.FOCUS_DOWN);
if(focusableView != null) focusableView.requestFocus();
new to android.. tried
getWindow().getDecorView().clearFocus();
it works for me..
just to add .. your layout should have:
android:focusable="true"
android:focusableInTouchMode="true"
Just find another view and give it focus instead.
var refresher = FindViewById<MvxSwipeRefreshLayout>(Resource.Id.refresher);
refresher.RequestFocus();
Did you try to use old good View.clearFocus()