Android show Keyboard by default

Problem

Sometimes we the Keyboard doesn’t show up by default if we e.g. open a dialog and request the focus for an input element. Even following the default tutorials doesn’t really help. As soo here some samples how it will show up.

Solution

Show Keyboard in Dialogs / DialogFragment

Usually the solution the the Android Guide  just works using:

Solution 1

Solution 2

My personal experience was, that this (solution 1) isn’t really working always — more the happy case. More reliable is the following solution:

This solutions also just works with the normal AlertDialog as it uses the show listener.

Important to note is, that in either case requestFocus should either be called or set in the xml layout file for the element.

Solution 3: Always show they Keyboard

Where is alway the possibility to always show the keyboard — even if not always really useful:

The keyboard could now be shown even if the user can’t input something into any input element. Where in solution 2 the keyboard is only shown of the element gets the focus, in this case the keyboard is just shown.

Request Focus for an Element using XML Layout File

Just add the Tag <requestFocus /> to the body of the element.

 

Paul Sterl has written 17 articles

2 thoughts on “Android show Keyboard by default

  1. Shaishav Bhatt says:

    You are right that first solution did not work some times.
    In my case always first solution did not work but your second solution always works.

    Thanks for help.

  2. Vimal R says:

    You are right that first solution did not work some times.
    In my case always first solution did not work but your second solution always works.

    Thanks for help.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">