Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent EditText from automatically focusing

I have an Android activity and there is one EditText 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 OnStart:

    FindViewById<EditText> (Resource.Id.searchText).ClearFocus ();
    FindViewById<EditText> (Resource.Id.searchText).Selected = false;
    
  • Adding a LinearLayout with these two properties:

    android:focusable="true" android:focusableInTouchMode="true"
    
  • Adding the following tag inside another View on the layout:

    android:focusable="true" android:focusableInTouchMode="true"
    
  • Adding this to my activity manifest:

    android:windowSoftInputMode="stateHidden"
    

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

like image 975
James Monger Avatar asked Dec 07 '25 03:12

James Monger


2 Answers

Try these for Xamarin.Android (Cross Platform)

this.Window.SetSoftInputMode (SoftInput.StateHidden);

Or

Add this to manifest,

[Activity(Label = "SampleApp", MainLauncher = true, Icon = "@drawable/icon", WindowSoftInputMode = SoftInput.StateHidden)]
like image 134
Nitin V. Patil Avatar answered Dec 08 '25 15:12

Nitin V. Patil


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

like image 43
kirankk Avatar answered Dec 08 '25 15:12

kirankk