0

I have an Editor in MAUI that as of now allows for tapping but each time I tap, it opens up the keyboard (on Android). I do want to be able to tap so that I can change cursor position but don't want for keyboard to appear at all. All the inputs that are accepted are through buttons and I programatically update the Editor.

I tried using KeyboardExtensions.HideKeyboardAsync(https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/extensions/keyboard-extensions), TapGestureRecognizer and Activity(https://github.com/dotnet/maui/discussions/4907), Editor.InputTransparent, ContentPage.HideSoftInputOnTapped(https://docs.telerik.com/devtools/maui/knowledge-base/hide-softkeyboard-without-losing-focus-maui-entry), Option 2 on the same website(https://docs.telerik.com/devtools/maui/knowledge-base/hide-softkeyboard-without-losing-focus-maui-entry).

These methods end up fully disabling the ability to access the Editor so none od them solved the problem. Im looking for a general approach (any platform) or at least something Android-specific. Is there a way to hide the keyboard while mainting the cursor position?

1 Answer 1

1

I think that for this kind of customization you have to use handlers.

I tried something like this and it seems to work for Android. You should probably organize it better than I did... it was just a PoC.

  1. Define a custom control that inherits from Entry.
  2. Define a method that customize the handler for your custom control.

NoKeyboardEntry.cs

namespace YourApp;

public class NoKeyboardEntry : Entry
{
    public static void SetHandler()
    {
        Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("NoKeyboardEntryCustomization", (handler, view) =>
        {
            if (view is NoKeyboardEntry)
            {
#if ANDROID
                handler.PlatformView.ShowSoftInputOnFocus = false;
#endif
            }
        });
    }
}
  1. Call the method (in my case NoKeyboardEntry.SetHandler();) somewhere. I did it on CreateMauiApp().

Edit

I realized you need an Editor and not an Entry. The procedure should be the same, just replace all the occurrences of "Entry" with "Editor" and you should be ready to go.

Sign up to request clarification or add additional context in comments.

5 Comments

Your solution worked well. Unfortunately, it does not work with an Editor, just an Entry. I do not mind changing mine Editor into an Entry so I accepted your answer. Thank you.
Just out of curiosity, what does not work with Editor? I tried and it seems to do the same. Also, the Android native component is the same for both Entry and Editor (AppCompatEditText), so there shouldn't be any difference.
For me, the keyboard still pops up when I revert to the Editor.
Are you sure you're replacing every occurence of "Entry"? I would say the minimum for it to work is replacing inheritance : Entry with : Editor and EntryHandler with EditorHandler inside SetHandler(). Maybe did you forgot the last one?
Oh yeah you are right, I forgot to change the handler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.