2016-09-22 51 views
5

我正在對Xamarin(Android)。現在我想要隱藏鍵盤後點擊外部Edit Text如何在Xamarin Android中隱藏鍵盤後單擊外部編輯文字

在此先感謝。

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

回答

5

使用此代碼隱藏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; 
+0

感謝您的答覆。我剛剛嘗試了上面的代碼,但沒有改變。 Still鍵盤正在出現。 – raji

+0

@raji看到我的更新答案。 – Ironman

+0

謝謝@Ironman。現在它正在工作。 – raji