4

I am currently studying soft keyboard implementation in android. One thing I am confused with is where to implement the popup little square when you press any key (I attach two example below).

I have read through the sample app "Soft Keyboard" provided in SDK, it has this feature, but I can't find which piece of code implements it.

Any ideas how I could implement/modify it?

Sample app "Soft keyboard"

sample keyboard

android default keyboard

android default keyboard

Ricardo A.
  • 685
  • 2
  • 8
  • 35
Yulong
  • 1,529
  • 1
  • 17
  • 26
  • I just found a SO post that should be what I need [here](http://stackoverflow.com/questions/7752580/creating-a-softkeyboard-with-multiple-alternate-characters-per-key) and [here](http://stackoverflow.com/questions/7770099/how-do-you-disable-the-softkeyboard-key-preview-window). Could anyone close my question? Thanks! – Yulong Dec 20 '12 at 16:59
  • To close a question. Just tick an answer. And write one yourself for future visitors if you feel you need to – cjds Dec 20 '12 at 17:46
  • Related: [Hide Android keyboard key preview](http://stackoverflow.com/q/9996968/1267663) – Whymarrh May 08 '17 at 17:33

2 Answers2

1

This is your preview layout.

A example of code for the preview.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:gravity="center"
android:textColor="@color/black"
android:textSize="30sp"
android:textStyle="bold" >

</TextView>

Call your preview on your keyboardView's xml:

android:keyPreviewLayout="@layout/preview"

Or you can create a class that extends KeyboardView and implement your own code for preview.

Ricardo A.
  • 685
  • 2
  • 8
  • 35
0

The part that controls this resides in LatinKeyboardView class

@Override
protected boolean onLongPress(Key key) {
    if (key.codes[0] == Keyboard.KEYCODE_CANCEL) {
        getOnKeyboardActionListener().onKey(KEYCODE_OPTIONS, null);
        return true;
    } else {
        return super.onLongPress(key);
    }
}

The part your looking at is in the else.

Now this calls super.onLongPress(key) which resides in KeyboardView.

To customize override the else with respective code.

You'll find the reference here

cjds
  • 8,268
  • 10
  • 49
  • 84
  • yeah I tried to add my conditions. But theres no code there for default layout right? Like, how could I modify the popup window, say, its size, or the content it displays? – Yulong Dec 20 '12 at 16:13
  • Hi I just found some relevant posts about my question like I add above in comments. But thank you for your help; appreciated it. – Yulong Dec 20 '12 at 16:59