Quantcast
Channel: User Liyun Zhang - MSFT - Stack Overflow
Viewing all articles
Browse latest Browse all 445

Answer by Liyun Zhang - MSFT for How do I re-enable the keyboard for Entry controls after disabling them?

$
0
0

The easiest way to do that is using the following code:

#if ANDROID     ( MyEntry.Handler.PlatformView as AndroidX.AppCompat.Widget.AppCompatEditText).ShowSoftInputOnFocus = true;#endif

And you can also custom the handler to disable or enable it:

CustomHandler.cs:

namespace MauiAppTest.Platforms.Android{    public class MyHandler : EntryHandler    {        public void DisableKeyboard()        {            PlatformView.ShowSoftInputOnFocus = false;        }        public void EnableKeyboard()        {            PlatformView.ShowSoftInputOnFocus = true;        }    }}

Use it in the MauiProgram.cs:

builder                .UseMauiApp<App>()                .UseMauiCommunityToolkit()                .ConfigureFonts(fonts =>                {                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");                })                .ConfigureMauiHandlers((handlers) =>                {#if ANDROID                    handlers.AddHandler(typeof(Entry),typeof(Platforms.Android.MyHandler));#endif                });

Call the method in the code behind:

#if ANDROID    (MyEntry.Handler as Platforms.Android.MyHandler).DisableKeyboard();#endif

In addition, when you change the property, you need to refocus the entry to show the KeyBoard.


Viewing all articles
Browse latest Browse all 445

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>