I have an issue when the activity starts, android automatically places focus on the first edittext. How do I prevent android from doing that?
Asked
Active
Viewed 2.3k times
3 Answers
1
Three ways to solve this..
Set these attributes to the parent..
And now, when activity starts this layout getting default focus.
Also we can remove focus from children views in runtime (e.g. after finishing child editing):
findViewById(R.id.mainLayout).requestFocus(); or
Look in the AndroidManifest.xml element.
android:windowSoftInputMode="stateHidden"
It always hide key board when entering the activity.

Zar E Ahmer
- 33,936
- 20
- 234
- 300
1
use setFocusable (boolean focusable) to prevent. http://developer.android.com/reference/android/view/View.html#setFocusable(boolean)

Ajay Singh
- 1,611
- 3
- 22
- 29
-
4The question is how to prevent automatically focus, not how to set it to un-focused. – chengbo Dec 19 '12 at 02:30
-
@cheng "To change whether a view can take focus, call setFocusable(boolean)" - http://developer.android.com/reference/android/view/View.html#setFocusable(boolean) – samus Feb 28 '13 at 21:30