最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to disable keyboard from appearing while allowing selection on an Editor in .NET MAUI? - Stack Overflow

programmeradmin1浏览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(), TapGestureRecognizer and Activity(), Editor.InputTransparent, ContentPage.HideSoftInputOnTapped(), Option 2 on the same website().

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?

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/en-us/dotnet/communitytoolkit/maui/extensions/keyboard-extensions), TapGestureRecognizer and Activity(https://github/dotnet/maui/discussions/4907), Editor.InputTransparent, ContentPage.HideSoftInputOnTapped(https://docs.telerik/devtools/maui/knowledge-base/hide-softkeyboard-without-losing-focus-maui-entry), Option 2 on the same website(https://docs.telerik/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?

Share Improve this question edited Mar 13 at 18:49 Nikola Savić asked Mar 13 at 9:28 Nikola SavićNikola Savić 91 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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 anize 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.

发布评论

评论列表(0)

  1. 暂无评论