How to instantiate an Activity with Edittext fields without being automatically selected?

Asked

Viewed 182 times

1

Developing an Android application, I came across a problem, I have an Activity where there are editing fields (Edittext) in xml, and when I instate it, the first Edittext field, is selected and the keyboard appears to fill, and I didn’t want the keyboard to appear, and q didn’t automatically select the field, basically by mounting an initial activity equal to the login of the Evernote app. And if there’s a way through the scheme of doing that Activity with the Tablayout, Viewpager, and the Parallax that he does best.

3 answers

3

A simple form is in the Androidmanifest.xml declare Activity in this way:

<activity android:name=".MainActivity"
          .....
          android:windowSoftInputMode="stateHidden"
          >

2

By default android always marks what contains the input with <autofocus/> or the first, a solution is in onCreate insert the following excerpt:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(seuInputText.getWindowToken(), 0);

1


Shift the focus to your Layout, as in the example below, taken from Soen:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true" >

Browser other questions tagged

You are not signed in. Login or sign up in order to post.