I have an
Activity in Android, with two elements:
Activity starts, the
EditText immediately has input focus (flashing cursor). I don't want any control to have input focus at startup. I tried:
No luck. How can I convince the
EditText to not select itself when the
Excellent answers from Luc and Mark however a good code sample is missing. Adding the tag
<LinearLayout> like the following example will fix the problem.
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus --> <LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="0px" android:layout_height="0px"/> <!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component to prevent the dummy from receiving focus again --> <AutoCompleteTextView android:id="@+id/autotext" android:layout_width="fill_parent" android:layout_height="wrap_content" android:nextFocusUp="@id/autotext" android:nextFocusLeft="@id/autotext"/>
Is the actual problem that you just don't want it to have focus at all? Or you don't want it to show the virtual keyboard as a result of focusing the
EditText? I don't really see an issue with the
EditText having focus on start, but it's definitely a problem to have the softInput window open when the user did not explicitly request to focus on the
EditText (and open the keyboard as a result).
If it's the problem of the virtual keyboard, see the
AndroidManifest.xml <activity> element documentation.
android:windowSoftInputMode="stateHidden" - always hide it when entering the activity.
android:windowSoftInputMode="stateUnchanged" - don't change it (e.g. don't show it if it isn't already shown, but if it was open when entering the activity, leave it open).