2014-07-01 40 views
2

我想顯示軟鍵盤,當我的edittext獲得焦點。 我寫下面的代碼來做到這一點。 但仍然鍵盤沒有出現,雖然我的編輯文字越來越關注。SoftKeyboard不包覆在xamarin android

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

回答

4

這是顯示軟輸入的實用方法。

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)); 
    }); 
} 

這是同一呼叫你的裏面,但我保證它運行在UI線程上,我發現我需要爲它工作在短暫的延遲。

這應該讓你工作。也許有人甚至可以改善我的:)

+0

您的解決方案爲我工作,謝謝@SpiritMachine – Suraj

+0

非常歡迎您。 – manadart