0

I have followed this solution on preventing edit text from taking focus on activity startup. And implemented it as such

<LinearLayout
        android:layout_width="0px"
        android:layout_height="0px"
        android:focusable="true"
        android:focusableInTouchMode="true"/>

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/amount"
        android:text="@string/zero"
        android:gravity="end|center_vertical"
        android:nextFocusUp="@id/amount"
        android:nextFocusLeft="@id/amount"
        android:inputType="numberDecimal"/>

Notice the android:inputType="numberDecimal". If I remove that then upon startup the focus is not taken, however if it is there then focus is taken. Is there any way to get decimal edit text to not take focus upon startup? I am using API > 23 if it is of any concern.

And just as a side note from looking at answers other people provided to similar questions, I want my field to not take focus. I do not want to only hide the soft keyboard but keep the focus.

Quillion
  • 6,346
  • 11
  • 60
  • 97

1 Answers1

1

Add this to your activity tag in manifest

android:windowSoftInputMode="stateHidden|adjustResize"

Code looks like in manifest

 <activity
            android:name=".ActivityName"
            android:windowSoftInputMode="stateHidden|adjustResize" />

This will help hide soft keyboard at startup

And add these tags to your root layout rather than parent layout

        android:focusable="true"
        android:focusableInTouchMode="true"
Quick learner
  • 10,632
  • 4
  • 45
  • 55
  • 1
    The thing that fixed it for me is adding `android:focusable="true"` `android:focusableInTouchMode="true"` To root layout instead of parent layout. Thank you!!! – Quillion Sep 11 '18 at 13:02