-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Soft Keyboard does not Pop Up when Entry View's Focus is set to True Programmatically #5983
Comments
Verified this issue with Visual Studio Enterprise 17.2.0 Preview 2.1 [32317.152]. Repro on Android. Sample Project: 5983.zip |
Still not working in GA. |
I've encountered the same problem. But when I use "Entry" inside Grid instead of StackLayout, it works just fine. Entry and StackLayout don't get along yet. |
I've encountered a different problem. Keyboard is not hiding when unfocus entry. I made a wordaround in handler: protected override void ConnectHandler(AppCompatEditText platformView)
{
base.ConnectHandler(platformView);
if (VirtualView is Entry entryControl)
entryControl.ObserveUnfocused().Subscribe(UnfocusedSubscription);
}
private void UnfocusedSubscription(FocusEventArgs args)
{
if (!args.IsFocused)
{
InputMethodManager inputMethodManager = (InputMethodManager)global::Android.App.Application.Context.GetSystemService(global::Android.Content.Context.InputMethodService);
inputMethodManager.HideSoftInputFromWindow(PlatformView.WindowToken, HideSoftInputFlags.None);
}
} I use own observable method, but you can use events. |
Many thanks marcoablanco. |
Can you give me more context how to use this in a sample app. I cannot figure out where I put these code of yours... |
I created a EntryHandler for Maui Entry control in Android folder. You can see more about Handler in https://docs.microsoft.com/dotnet/maui/user-interface/handlers/customize |
Adding It just dont fire on unfocused. |
Defocus_issue.zip |
Your handler is not registered. I added to MauiProgram and works. var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
#if ANDROID
.ConfigureMauiHandlers(handlers => handlers.AddHandler<Microsoft.Maui.Controls.Entry, Survey.Handlers.EntryHandler>())
#endif
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
return builder.Build(); I changed a little bit your handler public partial class EntryHandler : Microsoft.Maui.Handlers.EntryHandler
{
protected override void ConnectHandler(AppCompatEditText platformView)
{
base.ConnectHandler(platformView);
platformView.FocusChange += PlatformView_FocusChange;
}
protected override void DisconnectHandler(AppCompatEditText platformView)
{
base.DisconnectHandler(platformView);
platformView.FocusChange -= PlatformView_FocusChange;
}
private void PlatformView_FocusChange(object sender, Android.Views.View.FocusChangeEventArgs args)
{
if (args.HasFocus)
{
InputMethodManager inputMethodManager = (InputMethodManager)global::Android.App.Application.Context.GetSystemService(global::Android.Content.Context.InputMethodService);
inputMethodManager.ShowSoftInput(PlatformView, ShowFlags.Forced);
}
else
{
InputMethodManager inputMethodManager = (InputMethodManager)global::Android.App.Application.Context.GetSystemService(global::Android.Content.Context.InputMethodService);
inputMethodManager.HideSoftInputFromWindow(PlatformView.WindowToken, HideSoftInputFlags.None);
}
}
} |
Thank you for tweaking the sample, looks much better! Im still struggling to make the sample work, it does not lose focus. I hope there are things here i dont understand .. :) |
|
Surprised to see ! It isn't working till today. |
I can confirm this works when called from Windows platform code, I came across the same link as @relecon and chanced my arm. Added a more detailed explanation here: |
I added a mapper here that you can copy to add this behavior for android. One thing to note is that if your intention is to open the keyboard you should use Using |
Try this solution `private async void OnShowKeyboardTapped(object sender, EventArgs e) private async void OnHideKeyboardTapped(object sender, EventArgs e) private void KeyboardVisibility(bool StateFocus) |
### Description of Change Show keyboard on Android entry/editor/searchbar focus ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #5983 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
Show keyboard on Android entry/editor/searchbar focus <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #5983 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
Description
When Focus is set to an Entry view programmatically (entryTest.Focus()), the cursor blinks in the edit field of the Entry view, but the soft keyboard does not pop up as it should until you physically touch the Entry view. In comparison to Xamarin Forms where the keyboard pops up when executing entryTest.Focus().
Also, entryTest.Focus() is ignored when placed in the OnAppearing Event.
Video demo of Maui App:
SetFocusMaui.mp4
Video demo of Xamarin Forms version:
SetFocusXF.mp4
XAML:
Code Behind:
Steps to Reproduce
Version with bug
Preview 14 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 11
Did you find any workaround?
Workaround
I added a mapper here that you can copy to add this behavior for android.
One thing to note is that if your intention is to open the keyboard you should use
KeyboardManager.ShowKeyboard not
Focus
Using
Focus
to influence theKeyboard
has always felt like a hack to me in general.Relevant log output
No response
The text was updated successfully, but these errors were encountered: