I Want to show and dismiss the keyboard on edit Text ??

veeru3112veeru3112 INMember ✭✭

I have showed Numeric keyboard on edit Text by using the following code,

InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.NotAlways);

now if i press the Home button of the device it still show me the keyboard,
Please help me out to resolve this issue
Thanks in advance.

Best Answer

  • veeru3112veeru3112 IN ✭✭
    Accepted Answer

    Got the solution, use following code in onPause(),

    InputMethodManager inputManager = (InputMethodManager)GetSystemService(Context.InputMethodService);
    var currentFocus = this.CurrentFocus;
    if (currentFocus != null)
    {
    inputManager.HideSoftInputFromWindow(currentFocus.WindowToken, HideSoftInputFlags.None);
    }

    --
    Thanks
    Virendra

Answers

  • veeru3112veeru3112 INMember ✭✭
    Accepted Answer

    Got the solution, use following code in onPause(),

    InputMethodManager inputManager = (InputMethodManager)GetSystemService(Context.InputMethodService);
    var currentFocus = this.CurrentFocus;
    if (currentFocus != null)
    {
    inputManager.HideSoftInputFromWindow(currentFocus.WindowToken, HideSoftInputFlags.None);
    }

    --
    Thanks
    Virendra

  • KayKuoKayKuo Member ✭✭✭

    @veeru3112 sorry,I have a Xamarin.forms project, I have a page with an Entry control, I want to hide the keyboard when the Entry gets the focus ,because it is for scanning barcode labels, how can I achieve that?
    The following code can implement hidden keyboard, but the keyboard occasionally shows,especially when the entry is empty.
    How can I avoid it?thanks
    here is my caode :
    Control.InputType = 0;
    Control.ShowSoftInputOnFocus = false;
    InputMethodManager inputMethodManager = Control.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
    inputMethodManager?.HideSoftInputFromWindow(Control.WindowToken, HideSoftInputFlags.None);

Sign In or Register to comment.