Hide soft input panel in Xamarin Android application on EditText focus

1.4k Views Asked by At

I'v been developing a Xamarin Android application and my activity contains multiple edittexts. When I focus the edittext by clicking on it the soft input panel appears, but I want this to remain hidden at all times. I already tried with the underlying code, but this doesn't work and I also tried with CurrentFocus instead of the edittext.

InputMethodManager keyboard = (InputMethodManager)GetSystemService(Context.InputMethodService);
keyboard.HideSoftInputFromWindow(txtWerf.WindowToken, HideSoftInputFlags.None);

Further I tried with windowsoftinputmode in the xml of my layout and in the manifest file.

EDIT

 <application android:label="WMS" android:icon="@drawable/Icon">
 <activity android:name="Materiaal" android:windowSoftInputMode="stateAlwaysHidden"></activity>
 </application>

Does anyone as an idea?

3

There are 3 best solutions below

0
NiAu On BEST ANSWER

On each Edittext control you can set .ShowSoftInputOnFocus to false and the keyboard will not popup when clicking the edittext.

3
Kristo On

Try the code below which works for me.

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your focused view.

 // Check if no view has focus:
 View view = this.getCurrentFocus();
 if (view != null) {  
 InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
  }

This will force the keyboard to be hidden in all situations You can even try in the manifest under your activity this.

 android:windowSoftInputMode="stateAlwaysHidden"
0
darrk On

Or you can just use activity attribute with WindowSoftInputMode property:

[Activity(WindowSoftInputMode = SoftInput.StateAlwaysHidden)]