SoftKeyboard在xamarin android中没有出现

Sur*_*raj 2 xamarin.android xamarin xamarin-studio

当我的edittext获得焦点时,我想显示软键盘.我写了以下代码来做到这一点.但是,尽管我的edittext正在获得焦点,但仍然没有出现键盘.

   private void VerifyCodeEditText_FocusChange(object sender, View.FocusChangeEventArgs e)
    {
        if(e.HasFocus)
        {
            var inputManager = (InputMethodManager)GetSystemService(Context.InputMethodService);
            inputManager.ShowSoftInput(VerifyCodeEditText, ShowFlags.Implicit);
        }
    }
Run Code Online (Sandbox Code Playgroud)

man*_*art 6

这是我用于显示软输入的实用方法.

private void ShowSoftKeyboard(View input, bool selectText)
{
    if (selectText) ((EditText)input).SelectAll();
    ThreadPool.QueueUserWorkItem(s =>
    {
        Thread.Sleep(100); // For some reason, a short delay is required here.
        RunOnUiThread(() => ((InputMethodManager)GetSystemService(InputMethodService)).ShowSoftInput(input, ShowFlags.Implicit));
    });
}
Run Code Online (Sandbox Code Playgroud)

它与你的内部呼叫相同,但我确保它在UI线程上运行,我发现我需要一个短暂的延迟才能工作.

这应该让你工作.也许有人甚至可以提高我的:)