Create an IME (keyboard)

CaioshinCaioshin ITMember ✭✭

Hello,
I'm evaluating feasibility and efforts required to create an IME (I need a custom keyboard) in Xamarin for Android.
I need to replace the default Android keyboard with mine, is this possible?
Does somebody can place me in the right direction? (I looked for a demo project but I didn't found it)

Thank you

Tagged:

Answers

  • CaioshinCaioshin ITMember ✭✭

    little up

  • Mario3657168Mario3657168 MKMember

    I'm interested too, I've made this but it is not working well

    `
    ...
    class MyInputMethodService : InputMethodService, KeyboardView.IOnKeyboardActionListener
    {
    public override View OnCreateInputView()
    {
    KeyboardView keyboardView = (KeyboardView)LayoutInflater.Inflate(Resource.Layout.keyboard_view, null);
    Keyboard keyboard = new Keyboard(this, Resource.Xml.number_pad);
    keyboardView.Keyboard = keyboard;
    keyboardView.OnKeyboardActionListener = this;
    return keyboardView;
    }

        void KeyboardView.IOnKeyboardActionListener.OnKey(Android.Views.Keycode primaryCode, Android.Views.Keycode[] keyCodes)
        {
            if (CurrentInputConnection == null)
                return;
            switch(primaryCode)
            {
                case Android.Views.Keycode.Del:
                    ICharSequence selectedText = CurrentInputConnection.GetSelectedTextFormatted(flags: Android.Views.InputMethods.GetTextFlags.None);
                    if(Android.Text.TextUtils.IsEmpty(selectedText))
                    {
                        CurrentInputConnection.DeleteSurroundingText(1, 0);
                    }
                    else
                    {
                        ICharSequence text = new Java.Lang.String("");
                        CurrentInputConnection.CommitText(text, 1);
                    }
                    CurrentInputConnection.DeleteSurroundingText(1, 0);
                    break;
                default:
                    ICharSequence code = new Java.Lang.String(primaryCode.ToString());                    
                    CurrentInputConnection.CommitText(code, 1);
                    break;
            }
        }
    
        void KeyboardView.IOnKeyboardActionListener.OnPress(Android.Views.Keycode primaryCode)
        {
        }
    
        void KeyboardView.IOnKeyboardActionListener.OnRelease(Android.Views.Keycode primaryCode)
        {
        }
    
        void KeyboardView.IOnKeyboardActionListener.OnText(ICharSequence text)
        {
        }
    
        void KeyboardView.IOnKeyboardActionListener.SwipeDown()
        {
        }
    
        void KeyboardView.IOnKeyboardActionListener.SwipeLeft()
        {
        }
    
        void KeyboardView.IOnKeyboardActionListener.SwipeRight()
        {
        }
    
        void KeyboardView.IOnKeyboardActionListener.SwipeUp()
        {
        }
    }
    

    ...
    `

    with manifest
    ... <application android:allowBackup="true" android:label="@string/app_name"> <service android:name=".MyInputMethodService" android:permission="android.permission.BIND_INPUT_METHOD"> <intent-filter> <action android:name="android.view.InputMethod"/> </intent-filter> <meta-data android:name="android.view.im" android:resource="@xml/method"/> </service> </application> ...

Sign In or Register to comment.