How do I re-enable the keyboard for Entry controls after disabling them?

I have a barcode app where I need to disable the keyboard for an entry control.

I found this and it works great.
Preventing software keyboard from opening when clicking on an entry field in MAUI?

var builder = MauiApp.CreateBuilder();
    builder
    .UseMauiApp<App>()
    .ConfigureFonts(fonts =>
    {
        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
        fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
    });
    Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("NoKeyboardEntry", (handler, entry) =>
    {
        #if ANDROID
            handler.PlatformView.ShowSoftInputOnFocus = false;
        #endif
    })

But I also have to support a manual entry mode.

I tried this but it doesn’t work.

MyEntry.ShowKeyboardAsync(CancellationToken.None);

How do I enable the keyboard while the app is running after disabling it on start up using this method?

Edit:
So many people have been asking about how to handle this so here is my solution on how to use an Entry to get HID barcode scan input. I have a keep focus checkbox that when checked keeps the focus on the Entry and DISABLES TOTALLY the soft keyboard from displaying for the one Entry control! When the checkbox is unchecked the keyboard is re-enabled for the Entry. Perfect!

A BIG Thanks to Liyun Zhang for the enable/disable keyboard part.

// For HID barcode scanning
// Checking this checkbox will
// Keep the focus on the barcode Entry and
// Also disable the Entry keyboard!
<CheckBox x:Name="cb_KeepFocus" CheckedChanged="OnKeepFocusClicked"/>

// Entry that accepts the HID barcode
<Entry x:Name="tx_ConfirmationNumber"/>

public MainPage()
{
    InitializeComponent();

    // If the barcode Entry looses focus set it back every 3 seconds
    var KeepFocusTimer = Application.Current.Dispatcher.CreateTimer();
    KeepFocusTimer.Interval = TimeSpan.FromSeconds(3);
    KeepFocusTimer.Tick += (s, e) => OnKeepFocusTimer();
    KeepFocusTimer.Start();
}

private void    OnKeepFocusTimer()
{
    MainThread.BeginInvokeOnMainThread(() =>
    {
        if (cb_KeepFocus.IsChecked)
            // Only set the focus if it isn't already set
            if (!tx_ConfirmationNumber.IsFocused)
                tx_ConfirmationNumber.Focus();
    });
}

// Turns on and off the keep focus and keyboard for the HID Entry
private void    OnKeepFocusClicked(object sender, CheckedChangedEventArgs e)
{
    if (cb_KeepFocus.IsChecked && (!tx_ConfirmationNumber.IsFocused))
        tx_ConfirmationNumber.Focus();
    if (cb_KeepFocus.IsChecked)
        DisableKeyboard();
    else
        EnableKeyboard();
}

private void DisableKeyboard()
{
    #if ANDROID
        (tx_ConfirmationNumber.Handler.PlatformView as AndroidX.AppCompat.Widget.AppCompatEditText).ShowSoftInputOnFocus = false;
    #endif
}
private void EnableKeyboard()
{
    #if ANDROID
        (tx_ConfirmationNumber.Handler.PlatformView as AndroidX.AppCompat.Widget.AppCompatEditText).ShowSoftInputOnFocus = true;
    #endif
}

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.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật