Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing auto focus of EditText in an AlertDialog

I am having some trouble preventing an EditText within an AlertDialog automatically obtaining focus and displaying the keyboard.

The presenting activity has windowSoftInputMode=stateHidden and EditTexts within that don't get focus when the activity loads. But when the dialog is shown the keyboard automatically appears.

How do I prevent my AlertDialog from showing the keyboard when it is shown?

like image 726
fraserh Avatar asked Aug 08 '14 10:08

fraserh


Video Answer


1 Answers

If you have a custom layout for your AlertDialog you can use a dummy view that get the focus instead of your edittext:

<!-- Dummy view -->
<View
    android:layout_width="0dp" 
    android:layout_height="0dp"
    android:focusable="true" 
    android:focusableInTouchMode="true"/>

Try to put that view before your edittext.

like image 150
AlexBalo Avatar answered Sep 27 '22 18:09

AlexBalo