James Monger James Monger - 1 year ago 71
Android Question

Prevent EditText from automatically focusing

I have an Android activity and there is one

in the whole layout. For some reason, whenever the activity starts, the keyboard comes up.
I have tried all of the following things:

  • Placing these two in

    FindViewById<EditText> (Resource.Id.searchText).ClearFocus ();
    FindViewById<EditText> (Resource.Id.searchText).Selected = false;

  • Adding a
    with these two properties:

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

  • Adding the following tag inside another
    on the layout:

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

  • Adding this to my activity manifest:


But still, the keyboard opens when the activity opens. What could I be doing wrong?

Answer Source

Try this -this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download