Skip to content Skip to sidebar Skip to footer

Make Popup Of The Key Pressed In A Customized Keyboard

I'm using keyboardview to have my own keyboard. Works fine, but I cannot do the effect of enlarging the key pressed, as does the Android keyboard These are the parts that use <

Solution 1:

For just showing the enlarged previews, KeyboardView should be doing it by default. You don't want to set a popupKeyboard value as this is for a special mini keyboard that shows on long presses.

I assume you were following this tutorial. Take note of these lines in section 3.3:

// Do not show the preview balloons
mKeyboardView.setPreviewEnabled(false);

Instead set this to true.

Complete Solution

In your activity's layout:

<android.inputmethodservice.KeyboardView
    android:id="@+id/keyboardview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:keyPreviewOffset="12dp"
    android:keyPreviewLayout="@layout/kbpreview"
    android:visibility="visible" />

The important properties here are keyPreviewLayout, keyPreviewOffset and keyPreviewHeight.

layout/kbpreview.xml

<?xml version="1.0" encoding="utf-8"?><TextViewxmlns:android="http://schemas.android.com/apk/res/android"xmlns:gb="http://schemas.android.com/apk/res-auto"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="10dp"android:background="@color/red"android:textSize="30dp" />

xml/kb.xml

<?xml version="1.0" encoding="utf-8"?><Keyboardxmlns:android="http://schemas.android.com/apk/res/android"android:keyWidth="12.50%p"android:keyHeight="10%p" ><Row><Keyandroid:codes="55"android:keyLabel="7"android:keyEdgeFlags="left" /><Keyandroid:codes="56"android:keyLabel="8" /><Keyandroid:codes="57"android:keyLabel="9" /><Keyandroid:codes="65"android:keyLabel="A"android:horizontalGap="6.25%p" /><Keyandroid:codes="66"android:keyLabel="B" /><Keyandroid:codes="55006"android:keyLabel="CLR"android:keyEdgeFlags="right"/></Row><!-- and whatever else... --></Keyboard>

In your activity code

KeyboardmKeyboard=newKeyboard(this, R.xml.kb);

    // Lookup the KeyboardViewKeyboardViewmKeyboardView= (KeyboardView) findViewById(R.id.keyboardview);

    // Attach the keyboard to the view
    mKeyboardView.setKeyboard(mKeyboard);

    // Key listener required
    mKeyboardView.setOnKeyboardActionListener(myListener);

Result

with the '5' key pressed:

enter image description here

You may also find it useful to check out the KeyboardView source code.

Post a Comment for "Make Popup Of The Key Pressed In A Customized Keyboard"