I create android app with xamarin + mvvmcross. I have an MvxAutoCompleteTextView in my MvxFragment. After writing in the MvxAutoCompleteTextView and clicking on the others controls, I want to hide the virtual keyboard. I use this code
public class MyFragment : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.frMy, null);
var autoComplete = view.FindViewById<MvxAutoCompleteTextView>(Resource.Id.acMy);
InputMethodManager inputManager = (InputMethodManager)inflater.Context.GetSystemService(Context.InputMethodService);
inputManager.HideSoftInputFromWindow(autoComplete.WindowToken, HideSoftInputFlags.None);
return view;
}
}
but this not work. How do I hide the keyboard?
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. This will force the keyboard to be hidden in all situations.
Simply disable the Gboard app on your emulator. To do that, go to Settings > Apps > Gboard, and then click the "DISABLE" button. If Gboard is not visible, make sure you select the three dots in the top right corner and select the "Show system" option.
It's in the "Keyboards & input methods" section of the menu. Tap Null Keyboard. Now, when you tap in a text field, no keyboard will appear. Tap a different keyboard under Current keyboard to re-enable the on-screen keyboard.
You can hide the soft keyboard giving focus to something that is not a "keyboard launcher" control, for example, the parent container of your auto-complete control.
parentContainer = FindViewById<LinearLayout>(Resource.Id.parentContainer);
parentContainer.RequestFocus();
Let´s say your parent container is a LinearLayout, you should allow it to get focus with these 2 properties:
<LinearLayout
android:id="@+id/parentContainer"
android:focusable="true"
android:focusableInTouchMode="true">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With