单击外部 Edittext 后如何在 Xamarin Android 中隐藏键盘
How to Hide keyboard in Xamarin Android after clicking outside Edittext
我正在研究 Xamarin(Android)。现在我想在 Edit Text
外部单击后隐藏键盘。
提前致谢。
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
RequestWindowFeature(WindowFeatures.NoTitle);
SetContentView(Resource.Layout.Main);
EditText Etusername= FindViewById<EditText>(Resource.Id.EtUname);
Etusername.SetHintTextColor(Color.Gray);
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(Etusername.WindowToken, 0);
}
使用此代码隐藏 Keyboard
。
public override bool OnTouchEvent(MotionEvent e)
{
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(Etusername.WindowToken, 0);
return base.OnTouchEvent(e);
}
并确保您必须添加此库:
using Android.Views.InputMethods;
我正在研究 Xamarin(Android)。现在我想在 Edit Text
外部单击后隐藏键盘。
提前致谢。
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
RequestWindowFeature(WindowFeatures.NoTitle);
SetContentView(Resource.Layout.Main);
EditText Etusername= FindViewById<EditText>(Resource.Id.EtUname);
Etusername.SetHintTextColor(Color.Gray);
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(Etusername.WindowToken, 0);
}
使用此代码隐藏 Keyboard
。
public override bool OnTouchEvent(MotionEvent e)
{
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(Etusername.WindowToken, 0);
return base.OnTouchEvent(e);
}
并确保您必须添加此库:
using Android.Views.InputMethods;