-6

How can I disable the keyboard for a specif entry?

I have tried using the MAUI Community Toolkit but have had no success.

2
  • Why do you use Entry and not say Label? Commented Nov 6 at 13:26
  • Could you say what you tried from the Community Toolkit? Commented Nov 6 at 13:33

3 Answers 3

1

Option 1. Just use Label as @Sinatr said.

Option 2. Set the Entry IsEnabled=false:

Elements that are not enabled will not receive focus or respond to input events.


(In case you meant programmatically hide the keyboard once the Entry is focused)

Option 1. If you want to use platform-specific code, you can take a look at this SO answer

Option 2. If you want to use CommunityToolkit KeyboardExtensions:

YourPage.xaml

<Entry x:Name="Password"/>

YourPage.xaml.cs

using CommunityToolkit.Maui.Core.Platform;

Password.HideKeyboardAsync(CancellationToken.None);

EDIT: Your comment below is giving important context (you should include it on the original question). You are not looking for a way of programmatically hide your system keyboard or disable it (like you said on your original question). What you are really looking for is a way of changing Entry text input. Instead of the system keyboard, you want your barcode scanner.

The easiest way of achieving what you are looking for is to create a custom Entry and then apply a Hadler to keep the focus but not showing system keyboard:

public class BarcodeScannerEntry : Entry { }

Then on your MauiProgram.cs use this Handler:

    Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("BarcodeScannerEntryHandler", (handler, entry) =>
    {
        if(entry is BarcodeScannerEntry barcodeScannerEntry)
        {
#if ANDROID
            handler.PlatformView.ShowSoftInputOnFocus = false;
#endif
        }
    });
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for understanding. I’m using a scanner device such as the EDA51 or Zebra TC70. In this scenario, when the entry field is focused, I want to restrict manual input so that users cannot type values — the value should only be entered when the physical scanner is triggered. I’m also trying to avoid using device-specific SDKs because I don’t want to be locked into a particular vendor or have to write separate code for each device
I have updated my answer after your comment
0

I have read from your comments that you are using "EDA51 or Zebra TC70". This you should put in your question because information like that is essential.

Android devices with physical keyboards are usually set up to not show their software keyboard when a numeric text field.

So the simple solution is to flag your password field to accept only numbers. I am using similar system to login in with a pin on datalogic/honeywell devices. But it should be the same on yours.

The suggested alternative for not showing keyboard on focus should work, but I know some hand held devices that will ignore this option, and display it anyway.

Also the suggested alternative for hiding the keyboard manually will work. There is timing issue if you try to hide it before it gets shown on focus, but it is technically 100% working solution. Also I like to use it with adjust pan option.

Comments

-1

Use the inputmethodmanager from either the view or context

fun Context.hideKeyboard(view: View) {
    val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
    inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}

fun View.hideKeyboard() {
    val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    imm.hideSoftInputFromWindow(windowToken, 0)
}

1 Comment

MAUI uses C#, that's not C# but Kotlin.

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.