Custom keyboard layout format

I made a special soft keyboard.

XML file:

<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyboard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#1B0A33"
    android:keyBackground="@drawable/pexeso_keyboard_key"
/>

      

Java source file:

public class PexesoKeyboard extends InputMethodService implements
        KeyboardView.OnKeyboardActionListener {

        private KeyboardView kv;
        private Keyboard keyboard;
        private boolean caps = false;

        @Override
        public View onCreateInputView() {
            kv = (KeyboardView)getLayoutInflater().inflate(R.layout.pexeso_keyboard, null);
            keyboard = new Keyboard(this, R.xml.pexeso_keyboard_map);
            kv.setKeyboard(keyboard);
            kv.setPadding(10, 10, 10, 10);
            kv.setOnKeyboardActionListener(this);
            kv.invalidateAllKeys();
                kv.setPreviewEnabled(false);
                return kv;
            }


             ..
             ..
             ..
}

      

It now looks like this:

enter image description here

And I want it to look like this: enter image description here

How do I customize the layout and what's the best solution? Any ideas are welcome

+3


source to share


1 answer


It was easier than I expected. I just edited the layout - added keyboard view to relative layout. Then added LayoutInflater to onCreateInputView ().

Java

@Override
    public View onCreateInputView() {

        LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = li.inflate(R.layout.pexeso_keyboard_layout, null);
        kvw = (KeyboardView)v.findViewById(R.id.keyboard);
        keyboard = new Keyboard(this, R.xml.pexeso_keyboard_map);
        kvw.setKeyboard(keyboard);
        kvw.setOnKeyboardActionListener(this);
        kvw.setPreviewEnabled(false);
        keyboardMinWidth = kvw.getKeyboard().getMinWidth();
        displayWidth = getApplication().getResources().getDisplayMetrics().widthPixels;
        kvw.invalidateAllKeys();
        return v;
    }

      

Markup



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/pxs_keyboard_background"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:gravity="center_vertical|bottom">

    <android.inputmethodservice.KeyboardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/keyboard"
        android:layout_margin="35dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/pxs_keyboard_background"
        android:keyBackground="@drawable/pexeso_keyboard_key"
        android:layout_centerHorizontal="true">
    </android.inputmethodservice.KeyboardView>

</RelativeLayout>

      

Preview

How it looks

+1


source







All Articles