Using Android xml in Xamarin Forms

ThomasNasbyThomasNasby USMember ✭✭

I'm creating a custom keyboard (eventually for iOS also) and the only resource I found was this GitHub project. After working on it for a bit I got it working..however this project is only Android and isn't cross platform. I tried making it work with PCL using renderers but it kind of requires two pieces to talk to each other:

           // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            mKeyboard = new Keyboard(this, Resource.Xml.keyboard2);
            mTargetView = (EditText)FindViewById(Resource.Id.target);

            mKeyboardView = (CustomKeyboardView)FindViewById(Resource.Id.keyboard_view);
            mKeyboardView.Keyboard = mKeyboard;

            mTargetView.Touch += (sender, e) =>
            {
                Log.Info("onTouch", "true");
                mTargetView.RequestFocus();
                ShowKeyboardWithAnimation();

                e.Handled = false;
                mTargetView.ShowSoftInputOnFocus = false;
            };

            mTargetView.FocusChange += (sender, e) =>
            {
                if (!mTargetView.IsFocused)
                {
                    mKeyboardView.Visibility = ViewStates.Gone;
                }
            };

            mKeyboardView.Key += (sender, e) => {
                long eventTime = JavaSystem.CurrentTimeMillis();
                KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.KeepTouchMode);

                this.DispatchKeyEvent(ev);
            };

There's a lot of pieces to account for..I'm not sure if I can get them all talking to each other correctly inside renderers. Is it possible to essentially delegate a ContentPage out to an Android xml? Or is there another solution for what I'm trying to do?

Best Answer

  • ThomasNasbyThomasNasby USMember ✭✭
    Accepted Answer

    After poking around it looks like I could use a custom renderer for the whole ContentPage as opposed to just the xml/xaml portion of it. There is a sample here.

Answers

  • ThomasNasbyThomasNasby USMember ✭✭
    Accepted Answer

    After poking around it looks like I could use a custom renderer for the whole ContentPage as opposed to just the xml/xaml portion of it. There is a sample here.

Sign In or Register to comment.