Disable Control Focus in .NET MAUI for Android

Learn to disable focus on controls like Entry and Button in .NET MAUI on Android by modifying handlers to prevent the soft keyboard or unwanted focus.

  1. Android
    Add the following code in the CreateMauiApp() method.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    EntryHandler.Mapper.AppendToMapping("NoKeyboardEntry", (handler, entry) =>
    {
    #if ANDROID
        // Hide the soft keyboard
        handler.PlatformView.ShowSoftInputOnFocus = false;
        handler.PlatformView.ImeOptions = Android.Views.InputMethods.ImeAction.ImeNull;
        handler.PlatformView.InputType = Android.Text.InputTypes.Null;
        handler.PlatformView.PrivateImeOptions = "";
    #endif
    });
    ButtonHandler.Mapper.AppendToMapping("Project.Buttons.NoSystemFocus", (handler, view) =>
    {
    #if ANDROID
        if (view is Button)
        {
            handler.PlatformView.FocusableInTouchMode = false;
            handler.PlatformView.Focusable = false;
        }
    #endif
    });
    
  2. Windows

Built with Hugo
Theme Stack designed by Jimmy