0

I have MainActivity, there is EditText and PinView for username and password. When I am opening MainActivity keyboard is popping up automatically.

How to prevent it?

In activit_main.xml

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/edtEmailLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/lblLogin">

                    <EditText
                        android:id="@+id/editText_mobile"
                        style="@style/lato_regular"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/toolbarHeight"
                        android:background="@drawable/edit_bottom_line"
                        android:drawablePadding="8dp"
                        android:gravity="center_vertical"
                        android:hint="@string/mobileNumber"
                        android:inputType="number"
                        android:maxLength="10"
                        android:padding="10dp"
                        android:paddingStart="@dimen/space_with_4dp"
                        android:singleLine="true"
                        android:textColor="@color/black"
                        android:textColorHint="@color/text_hint_color"
                        android:textSize="16sp"
                        />
                </android.support.design.widget.TextInputLayout>

In AndroidManifest.xml

        <activity
        android:name=".module.activity.signin.MainActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateAlwaysHidden">

        <!-- First activity -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

I also tried:

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

and

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Jacks
  • 735
  • 1
  • 4
  • 16
Makarand
  • 623
  • 4
  • 16

3 Answers3

1

I am using this and it is working totally fine. It is not showing keyword until i am clicking on it.. Even you should try..

<com.google.android.material.textfield.TextInputLayout
      android:id="@+id/text1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="16dp">

      <EditText
          android:id="@+id/username"
          style="@style/TextAppearance.AppCompat.Small"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dp"
          android:background="@android:color/transparent"
          android:drawableStart="@drawable/email_login"
          android:drawableLeft="@drawable/email_login"
          android:drawablePadding="12dp"
          android:hint="@string/usernameedit"
          android:imeOptions="actionNext"
          android:inputType="text"
          android:maxLength="32"
          android:maxLines="1"
          android:padding="13dp"
          android:textColor="@android:color/black"
          android:textColorHighlight="@android:color/tertiary_text_dark"
          android:textColorHint="@android:color/white" />

     <View
          android:layout_width="match_parent"
          android:layout_height="2dp"
          android:layout_below="@+id/username"
          android:layout_marginLeft="4dp"
          android:layout_marginRight="4dp"
          android:background="#f9d7db" />
</com.google.android.material.textfield.TextInputLayout>
Jakir Hossain
  • 3,426
  • 1
  • 11
  • 25
1

Add these two lines in the Root View in your XML layout

i.e. Root View Could be ContraintLayout or any other layout.

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" 
AbhayBohra
  • 1,827
  • 15
  • 31
0

Add these two lines to the parent of the EditText

android:focusable="true"
android:focusableInTouchMode="true"

Also you can use

windowSoftInputMode="stateAlwaysHidden" 

in the Activity Manifest @Makarand

pramod_m
  • 154
  • 1
  • 9