Hades
Hades

Reputation: 3936

Edittext android automatic focus

I have an issue when the activity starts, android automatically places focus on the first edittext. How do I prevent android from doing that?

Upvotes: 10

Views: 23411

Answers (3)

Zar E Ahmer
Zar E Ahmer

Reputation: 34390

Three ways to solve this..

  1. 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.

Upvotes: 1

SteD
SteD

Reputation: 14025

Have a look here

Or you could just hide the keyboard, focus remains on the EditText upon starting the activity:

android:windowSoftInputMode="stateHidden"

Upvotes: 15

Ajay Singh
Ajay Singh

Reputation: 1631

use setFocusable (boolean focusable) to prevent. http://developer.android.com/reference/android/view/View.html#setFocusable(boolean)

Upvotes: 1

Related Questions