2012-04-03 7 views
2

私は、一連のEditTextとボタンを備えたアクティビティを手に入れました。ユーザーがボタンをクリックすると、ボタンのキャプションにEditTextsからの入力に基づく回答が表示されます。 buttonclickハンドラでは、フォーカスをボタンに変更し、EditTextにフォーカスがあってもカーソルは消えますが、ソフトキーボードは画面上に残ります。ソフトキーボードを強制的に消滅させるにはどうすればよいですか?MonoDroidでソフトキーボードを非表示にする

EditText1.ClearFocus();  
EditText2.ClearFocus();  
EditText3.ClearFocus(); 
calc_btn.Focusable = true; 
calc_btn.RequestFocus(); 

私はJavaでこれを行う方法のように、いくつかの答えを見てきましたが、私は、C#にそれらを変換する方法を見つけ出すことができませんでした。

ありがとうございました。

答えて

3

:上記

var inputManager = (InputMethodManager)GetSystemService(InputMethodService); 
inputManager.HideSoftInputFromWindow(editText.WindowToken, HideSoftInputFlags.None); 
+0

完璧に動作します、グレッグ。どうもありがとう。 –

+0

これがなぜ私にとってうまくいかなかったのか分かりません。 – PCoder

1

thisはお役に立ちましたか?あなたはこのような何かを行うことができます

public override void HideSoftInput (int flags, Android.OS.ResultReceiver resultReceiver)

+0

私はそれを呼び出す方法を見つけ出すことができれば、その方法が役立つと確信しています。これはメソッドを生成しないため、直接実装されていないようです:Android.InputMethodServices.InputMethodService.InputMethodImpl。 –

+0

正しい答えを受け入れることを忘れないでください! :) –

2

Jon Oの答えは完璧です

はここに方法があるようです。これがあなたの使い方です。

using Android.Views.InputMethods; 

yourEditTextObject.EditorAction += (object sender, TextView.EditorActionEventArgs e) => 
     { 
      if (e.ActionId == Android.Views.InputMethods.ImeAction.Done) 
      { 
       var editText = sender as EditText; 
       var inputManager = GetSystemService(InputMethodService) as InputMethodManager; 
       inputManager.HideSoftInputFromWindow(editText.WindowToken, 0); 
      } 
     }; 
0

はここで完全に作業溶液であります、私はそれを間違って書いたことがありますか?

2
protected override void OnCreate (Bundle bundle) 
    { 
     base.OnCreate (bundle); 

     SetContentView (Resource.Layout.Main); 

     Button button = FindViewById<Button> (Resource.Id.button1); 
     button.Click+= onClick; 
     EditText es=FindViewById<EditText>(Resource.Id.editText1); 
     es.EditorAction += (object sender, TextView.EditorActionEventArgs e) => 
     { 

      if (e.ActionId == Android.Views.InputMethods.ImeAction.Done) 
      { 
       var editText = sender as EditText; 
       var inputManager = GetSystemService(InputMethodService) as InputMethodManager; 
       inputManager.HideSoftInputFromWindow(editText.WindowToken, 0); 
      } 

     }; 
     EditText es1=FindViewById<EditText>(Resource.Id.editText2); 
     es1.EditorAction += (object sender, TextView.EditorActionEventArgs e) => 
     { 
      if (e.ActionId == Android.Views.InputMethods.ImeAction.Done) 
      { 
       var editText = sender as EditText; 
       var inputManager = GetSystemService(InputMethodService) as InputMethodManager; 
       inputManager.HideSoftInputFromWindow(editText.WindowToken, 0); 
      } 
     }; 



    } 

私が働いていない、両方textboxs.Itsためのソフトキーパッドを表示したいいけない上記code.I内の指定されたメソッドを使用しています

Window.SetSoftInputMode(SoftInput.StateHidden); 
関連する問題