2

I develop using Xamarin.

When I click in Editor control keyboard shows up. I would like to have when user write message and clicks enter so keyobard going away or even somehow to hide keyboard when user undecided to write anything.

Is ther anyway to do so?

Ralf
  • 16,086
  • 4
  • 44
  • 68
DinoDin2
  • 121
  • 10

2 Answers2

2

You can also use

editor.UnFocus(); 
LeRoy
  • 4,189
  • 2
  • 35
  • 46
0

You try this. First create interface in your shared project

public interface IKeyboardHelper
{
    void HideKeyboard();
}

Implemented that in iOS project by adding new iOSKeyboardHelper.cs file

public class iOSKeyboardHelper : IKeyboardHelper
{
    public void HideKeyboard()
    {
        UIApplication.SharedApplication.KeyWindow.EndEditing(true);
    }
}

Now implement the same in your android project by adding new file DroidKeyboardHelper.cs

public class DroidKeyboardHelper : IKeyboardHelper
{
    public void HideKeyboard()
    {
        var context = Forms.Context;
        var inputMethodManager = context.GetSystemService(Context.InputMethodService) as InputMethodManager;
        if (inputMethodManager != null && context is Activity)
        {
            var activity = context as Activity;
            var token = activity.CurrentFocus?.WindowToken;
            inputMethodManager.HideSoftInputFromWindow(token, HideSoftInputFlags.None);    
            activity.Window.DecorView.ClearFocus();
        }
    }
}

Call your method in shared project like this, Wherever you need it.

DependencyService.Get<IKeyboardHelper>().HideKeyboard()

visit this & this for more information.

R15
  • 13,982
  • 14
  • 97
  • 173