0

enter image description here

hello I make simple application when I run that application my keyboard open automatically I want to remove focus from edit field or hide keyboard first time when application launch

here is my code

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

    <include
        android:id="@+id/top_header"
        layout="@layout/header_second_screen"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" />


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/footer_item"
        android:layout_below="@+id/top_header"
        android:background="#ee3333">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="20dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="UserName"
                    android:textColor="#ffffff"
                    android:textSize="20sp" />

                <EditText
                    android:id="@+id/entry"
                    android:layout_width="0dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="30dp"
                    android:layout_weight="1"
                    android:background="@drawable/border"
                    android:hint="Add Name"
                    android:padding="5dp"
                    android:singleLine="true"
                    android:textColor="#ffffff" />
            </LinearLayout>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#567234"
                android:text="Login"
                android:layout_gravity="center"/>

        </LinearLayout>

    </ScrollView>


    <include
        android:id="@+id/footer_item"
        layout="@layout/footer_second_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />


</RelativeLayout>
user944513
  • 12,247
  • 49
  • 168
  • 318
  • try this link will help you.http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard?page=2&tab=votes#tab-top – Vishwa Aug 18 '15 at 05:53
  • put it into android:windowSoftInputMode="adjustPan" activity in manifest. – Krishna V Aug 18 '15 at 05:54
  • possible duplicate of [How to hide Soft Keyboard when activity starts](http://stackoverflow.com/questions/18977187/how-to-hide-soft-keyboard-when-activity-starts) – Emil Aug 18 '15 at 05:54

3 Answers3

4

You can hide keyboard when your activity launches.

In the AndroidManifest.xml:

<activity android:name="com.your.package.ActivityName"
      android:windowSoftInputMode="stateHidden"  />

or try

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)‌​;

I hope it helps!

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
3

A simpler trick.

Just add the following XML attributes to your root RelativeView. Actually you need to make sure the view you're adding these attributes to is placed before the first EditText.

<RelativeLayout
...
android:focusable="true"
android:focusableInTouchMode="true"
...
> ... </RelativeLayout>

Let me know if this works for you.

akhy
  • 5,760
  • 6
  • 39
  • 60
0

Use this to hide your keyboard

public static void hideKeyboard( Activity activity ) {
        InputMethodManager imm = (InputMethodManager)activity.getSystemService( Context.INPUT_METHOD_SERVICE );
        View f = activity.getCurrentFocus();
        if( null != f && null != f.getWindowToken() && EditText.class.isAssignableFrom( f.getClass() ) )
            imm.hideSoftInputFromWindow( f.getWindowToken(), 0 );
        else 
            activity.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN );
    }
H4SN
  • 1,482
  • 3
  • 24
  • 43