2

I have a layout in which the first button keeps grabbing focus as soon as the activity is started (if in touch mode). Is there a way to politely ask the activity to not auto-focus? I know I can put in a focusable dummy layout with 0 width/height to do this, seems like there should be something better.

Reference: Set initial focus in an android application

Thanks

Community
  • 1
  • 1
user291701
  • 38,411
  • 72
  • 187
  • 285

1 Answers1

1

I had this problem too. I got around it by setting the focusable and focusableInTouchMode attributes to true in the parent LinearLayout.

android:focusable="true"
android:focusableInTouchMode="true"
Kevin Tighe
  • 20,181
  • 4
  • 35
  • 36
  • Yeah that works, but I mean what we really want is something like an activity flag, asking not to auto-focus the first item. I don't think something like that exists in android though? – user291701 Aug 15 '11 at 21:33
  • I don't know if that exists or not. Is there a particular reason you don't want anything to have focus? – Kevin Tighe Aug 16 '11 at 12:56
  • 1
    Yeah, it just looks a bit silly to have a control initially focused when landing on a new activity. – user291701 Aug 16 '11 at 13:49
  • Sorry, my comment was vague: I agree that it looks silly for a button to have focus automatically. I don't mind the parent view having focus though, because it is not visible to the user. – Kevin Tighe Aug 16 '11 at 13:58