Set initial focus in an Android application

stealthcopter picture stealthcopter · Apr 30, 2010 · Viewed 136.8k times · Source

In my Android application it automatically focuses the first Button I have in my layout, giving it an orange outline. How can I set the initial focus preferably in XML, and can this be set to nothing?

Answer

Matthias picture Matthias · Apr 30, 2010

You could use the requestFocus tag:

<Button ...>
  <requestFocus />
</Button>

I find it odd though that it auto-focuses one of your buttons, I haven't observed that behavior in any of my views.