簡體   English   中英

單擊外部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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM