我正在开发xamarin(android),现在我想在点击outsideEdit 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;

07-25 21:02