2

When i start Login Activity. it has two fields email and password. Email should get the focus but not open the keyboard automatically when the activity starts.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/splash_background_gradient" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginBottom="10dip"
        android:layout_marginTop="10dip"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/SplashLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="40dip"
            android:src="@drawable/splash_logo" />

        <EditText
            android:id="@+id/EmailAddress"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:hint="Email Address"
            android:maxLines="1" android:nextFocusRight="@+id/Password">


        </EditText>

        <EditText
            android:id="@+id/Password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="5dip"
            android:hint="Password"
            android:inputType="textPassword" />

        <Button
            android:id="@+id/Login"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="10dip"
            android:background="@drawable/login_button_selector"
            android:text="@string/login" />

        <TextView
            android:id="@+id/ForgotPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="28dp"
            android:layout_marginRight="28dp"
            android:layout_marginTop="10dip"
            android:text="@string/forgot_password"
            android:textColor="#000000"
            android:textSize="7pt"/>
    </LinearLayout>

</ScrollView>

2 Answers 2

7

You should add the attribute

android:windowSoftInputMode="stateAlwaysHidden"

to you activity in AndroidManifest.xml

1
  • damn.. was searching what to put in the XML all the while. thanks a lot :)
    – Harsha M V
    Oct 28, 2011 at 21:04
1

This technique suppresses the soft keyboard until the user touches an EditText

InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(YourClass.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {  // protection
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.