Example #1
0
        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;
        }
Example #2
0
        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);
        }