private void CreateCustomKeyboard() { var activity = (Activity)this.context; var rootView = activity.Window.DecorView.FindViewById(Android.Resource.Id.Content); var activityRootView = (ViewGroup)((ViewGroup)rootView).GetChildAt(0); this.mKeyboardView = activityRootView.FindViewById <Android.InputMethodServices.KeyboardView>(Resource.Id.customKeyboard); // If the previous line fails, it means the keyboard needs to be created and added if (this.mKeyboardView == null) { this.mKeyboardView = (Android.InputMethodServices.KeyboardView)activity.LayoutInflater.Inflate(Resource.Layout.CustomKeyboard, null); this.mKeyboardView.Id = Resource.Id.customKeyboard; this.mKeyboardView.Focusable = true; this.mKeyboardView.FocusableInTouchMode = true; this.mKeyboardView.Release += (sender, e) => { }; var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); layoutParams.AddRule(LayoutRules.AlignParentBottom); activityRootView.AddView(this.mKeyboardView, layoutParams); } this.HideKeyboardView(); this.mKeyboard = new Android.InputMethodServices.Keyboard(this.context, Resource.Xml.special_keyboard); this.SetCurrentKeyboard(); }
void SetupUserInterface() { activity = this.Context as Activity; view = activity.LayoutInflater.Inflate(Resource.Layout.activity_keyboard, this, false); mKeyboard = new Android.InputMethodServices.Keyboard(Context, Resource.Xml.keyboard); mTargetView = view.FindViewById <EditText>(Resource.Id.target); mKeyboardView = view.FindViewById <CustomKeyboardView>(Resource.Id.keyboard_view); mKeyboardView.Keyboard = mKeyboard; }
protected override TextInputLayout CreateNativeControl() { var textInputLayout = new TextInputLayout(Context); var editText = new EditText(Context); #region Add the Keyboard in your Page var activity = Forms.Context as Activity; var rootView = activity.Window.DecorView.FindViewById(Android.Resource.Id.Content); //activity.Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); // (SoftInput.StateAlwaysHidden); activityRootView = ((ViewGroup)rootView).GetChildAt(0) as ViewGroup; mKeyboardView = new CustomKeyboardView(Forms.Context, null); Android.Widget.RelativeLayout.LayoutParams layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); // or wrap_content layoutParams.AddRule(LayoutRules.AlignParentBottom); activityRootView.AddView(mKeyboardView, layoutParams); #endregion //First open the current page, hide the Keyboard mKeyboardView.Visibility = ViewStates.Gone; //Use the custom Keyboard mKeyboard = new Android.InputMethodServices.Keyboard(Context, Resource.Xml.keyboard); mKeyboardView.Keyboard = mKeyboard; mKeyboardView.Key += async(sender, e) => { if (e.PrimaryCode == Keycode.NavigateNext) { this.mKeyboardView.Visibility = ViewStates.Gone; // or this (not working yet) // https://forums.xamarin.com/discussion/58763/key-detection-on-form-plus-making-the-keyboard-disappear-on-a-device-with-physical-keys //var inputMethodManager = (InputMethodManager)this.Context.GetSystemService(Activity.InputMethodService); //this.mKeyboard.Dispose(); ////this.mKeyboardView.WindowToken //inputMethodManager.HideSoftInputFromWindow(this.mKeyboardView.WindowToken, 0); return; } long eventTime = JavaSystem.CurrentTimeMillis(); KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.EditorAction); DispatchKeyEvent(ev); await Task.Delay(1); }; textInputLayout.AddView(editText); return(textInputLayout); }
protected override TextInputLayout CreateNativeControl() { var textInputLayout = new TextInputLayout(Context); var editText = new EditText(Context); #region Add the Keyboard in your Page var activity = Forms.Context as Activity; var rootView = activity.Window.DecorView.FindViewById(Android.Resource.Id.Content); activity.Window.SetSoftInputMode(SoftInput.StateAlwaysHidden); activityRootView = ((ViewGroup)rootView).GetChildAt(0) as ViewGroup; mKeyboardView = new CustomKeyboardView(Forms.Context, null); Android.Widget.RelativeLayout.LayoutParams layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent); // or wrap_content layoutParams.AddRule(LayoutRules.AlignParentBottom); activityRootView.AddView(mKeyboardView, layoutParams); #endregion //First open the current page, hide the Keyboard mKeyboardView.Visibility = ViewStates.Gone; //Use the custom Keyboard mKeyboard = new Android.InputMethodServices.Keyboard(Context, Resource.Xml.keyboard); mKeyboardView.Keyboard = mKeyboard; mKeyboardView.Key += async(sender, e) => { long eventTime = JavaSystem.CurrentTimeMillis(); KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.KeepTouchMode); DispatchKeyEvent(ev); await Task.Delay(1); }; textInputLayout.AddView(editText); return(textInputLayout); }