0

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?

NiAu
  • 535
  • 1
  • 12
  • 32

3 Answers3

0

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"
Kristo
  • 1,339
  • 12
  • 22
  • thx for your answer, but this both doesn't work. The first I already tried with CurrentFocus.WindowToken and the second I now tried (see edited question), but when I give focus by clicking the control on the device the panel always pops up. – NiAu Jan 07 '16 at 12:12
  • Hmm no idea then I can't see a reason for this not to work. As I said I have used the code above on some of my projects and it did work. – Kristo Jan 07 '16 at 12:40
  • It is indeed very strange. When I use requestfocus the go from the first to next edittext the keyboard does not popup. It only happens by clicking the control. – NiAu Jan 08 '16 at 09:55
0

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

NiAu
  • 535
  • 1
  • 12
  • 32
0

Or you can just use activity attribute with WindowSoftInputMode property:

[Activity(WindowSoftInputMode = SoftInput.StateAlwaysHidden)]
darrk
  • 51
  • 4