1

I am building an android custom keyboard based on https://github.com/android/platform_development/tree/master/samples/SoftKeyboard

They have qwerty and symbols keyboard under res/xml folder. I have added a dummy keyboard (friendlist.xml) like below:

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
        android:keyWidth="20%p"
        android:horizontalGap="0px"
        android:verticalGap="0px"
        android:keyHeight="20%p"
        >

</Keyboard>

I need to add in "Key" programmatically into this Keyboard (friendlist.xml). In SoftKeyboard.java,

I added the following:

private LatinKeyboard mFriendlistKeyboard;

    @Override public void onInitializeInterface() {
        if (mQwertyKeyboard != null) {
            // Configuration changes can happen after the keyboard gets recreated,
            // so we need to be able to re-build the keyboards if the available
            // space has changed.
            int displayWidth = getMaxWidth();
            if (displayWidth == mLastDisplayWidth) return;
            mLastDisplayWidth = displayWidth;
        }
        mQwertyKeyboard = new LatinKeyboard(this, R.xml.qwerty);
        mSymbolsKeyboard = new LatinKeyboard(this, R.xml.symbols);
        mSymbolsShiftedKeyboard = new LatinKeyboard(this, R.xml.symbols_shift);
        mFriendlistKeyboard = new LatinKeyboard(this, R.xml.friendlist);

    }

But I couldn't find any function that can add Row and Key into the Keyboard at runtime.

Appreciate any help please. Thanks !

Cheerio, Mark Thien

Mark Thien
  • 1,108
  • 2
  • 22
  • 35

1 Answers1

0

There is an additional constructor that takes as parameters keys to add to the keyboard. Its limited to chars.

Keyboard Constructor source

 public Keyboard(Context context, int layoutTemplateResId, 
        CharSequence characters, int columns, int horizontalPadding);

Example for a dynamic keyboard that includes only vocals:

mFriendlistKeyboard = new Keyboard(this, R.xml.friendlist, 'AEIOU', -1, 0);

If you need more than just 'Character' keys, extending the keyboard its going to be necesary.

https://github.com/chrisboyle/sgtpuzzles/blob/master/app/src/main/java/name/boyle/chris/sgtpuzzles/SmallKeyboard.java

liloargana
  • 165
  • 1
  • 10
  • Is there any Example to explain for adding the extra Keys to Android Native Keyboard Programmatically. @liloargana – Roster Oct 20 '15 at 11:58
  • 1
    @Roster I believe it's not possible to add keys to the default native Keyboards because you dont get to instantiate it programatically. You might need to implement your own keyboard and mimic the default style. Check http://stackoverflow.com/questions/14528178/how-can-i-implement-special-soft-keyboard – liloargana Oct 20 '15 at 15:21
  • is there any solution provide for add row and keys runtime – Nitesh Khosla Aug 27 '16 at 12:35