I have a game built in Monogame targeting the Android and iOS platforms. I need to develop a login form for the game. I've begun to roll out my own UI components (text inputs, buttons, so forth), as I've read that there are no commonly used libraries for this purpose.

Now, I'm looking to access on the soft keyboard (for Android at the moment) but can't seem to get it working.

I've looked into the GamerServices module, but I'm pretty sure this only applies to Windows OSes.

I'm trying to implement what looks like the C# wrapper to the Android API. While debugging this code in Visual Studio 2015, the ShowKeyboard function executes without error, but the onscreen keyboard in the emulator doesn't appear.

I've added the following functions to my Android Activity class generated by Monogame, then access these functions when appropriate in-game. The code executes, but alas no keyboard.

    public static void ShowKeyboard()
        var pView = KeyboardConfig.game.Services.GetService<View>();
        var inputMethodManager = KeyboardConfig.Application.GetSystemService(Context.InputMethodService) as InputMethodManager;
        inputMethodManager.ShowSoftInput(pView, ShowFlags.Forced);
        inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);

    public static void HideKeyboard()
        InputMethodManager inputMethodManager = KeyboardConfig.Application.GetSystemService(Context.InputMethodService) as InputMethodManager;
        inputMethodManager.HideSoftInputFromWindow(KeyboardConfig.pView.WindowToken, HideSoftInputFlags.None);
  • 1
    \$\begingroup\$ I managed a rather hack-ish solution for Windows Phone. Basically I created a Textbox on the parent view (behind the whole game view) and gave it focus, and then monitored changes in that text field. It wasn't pretty, but it sure worked without a problem! Maybe you can do something similar? \$\endgroup\$ – Falgantil Aug 24 '16 at 13:41
  • \$\begingroup\$ It kind of sucks that we have to resort to hacks to get input into Monogame. \$\endgroup\$ – Nicholas Pickering Aug 24 '16 at 14:18
  • 1
    \$\begingroup\$ Very true, and it might not be the case for Android. I'm just saying that this was my only option back then for Windows Phone, so if all else fails it may be an alternative for Android. \$\endgroup\$ – Falgantil Aug 24 '16 at 15:00
  • \$\begingroup\$ I'm likely going to switch out of the monogame activity to get the input and pass it back. Thanks for the tips. \$\endgroup\$ – Nicholas Pickering Aug 24 '16 at 19:08

Instead of rolling out my own toolset for taking input, I push the users out to a non-Monogame Activity to take input and pass the results back. Works pretty well, even if the user experience is a little jagged.

I'll have to reimplement the forms for any other platforms I intend to support - but that was already a problem.

    // go to authentication screen
    private void launchPlatformAuthentication()
        #if __ANDROID__
            var intent = new Intent(Android.App.Application.Context, typeof(ActivityAuth));
            Activity1.ActivityConfig.Application.StartActivityForResult(intent, 0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.