Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove focus from single editText

Tags:

android

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 focusable view in this activity, I believe. My EditText shows with an orange border and cursor on the field.

Now I would like to remove the focus from this field (I don't want the cursor and border to show). Is there a way to do this?

I have been able to focus on the button by doing button.seFocusableInTouchMode() and button.requestFocus(). But this highlights the button and is obviously not what I want.

like image 831
tobbenb3 Avatar asked Oct 08 '10 11:10

tobbenb3


People also ask

How do I remove focus in EditText?

Remove focus but remain focusable: editText. setFocusableInTouchMode(false); editText. setFocusable(false); editText.

How to turn off focus Android?

Now, to turn on Focus Mode, simply tap the tile from the Quick Settings. You can also turn it off from the tile, or tap “Take a Break” from the notification to pause it for a bit.

How do I know if EditText has focus?

You can use View. OnFocusChangeListener to detect if any view (edittext) gained or lost focus. This goes in your activity or fragment or wherever you have the EditTexts.


2 Answers

new to android.. tried

getWindow().getDecorView().clearFocus(); 

it works for me..

just to add .. your layout should have:

 android:focusable="true"  android:focusableInTouchMode="true" 
like image 53
Zaraki Avatar answered Sep 21 '22 06:09

Zaraki


Did you try to use old good View.clearFocus()

like image 28
MishaZ Avatar answered Sep 18 '22 06:09

MishaZ