我用xamarin + mvvmcross创建了android应用。我的MvxFragment中有一个MvxAutoCompleteTextView。在MvxAutoCompleteTextView中写入并单击其他控件后,我想隐藏虚拟键盘。我用这个代码
public class MyFragment : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.frMy, null);
var autoComplete = view.FindViewById<MvxAutoCompleteTextView>(Resource.Id.acMy);
InputMethodManager inputManager = (InputMethodManager)inflater.Context.GetSystemService(Context.InputMethodService);
inputManager.HideSoftInputFromWindow(autoComplete.WindowToken, HideSoftInputFlags.None);
return view;
}
}
但这行不通。如何隐藏键盘?
尝试这个:
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(autoComplete.WindowToken, 0);
值0
中HideSoftInputFromWindow
是常量Android.Views.InputMethods.HideSoftInputFlags.None
,所以你可以使用等效语法:
InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(autoComplete.WindowToken, Android.Views.InputMethods.HideSoftInputFlags.None);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句