我正在构建基于https://github.com/android/platform_development/tree/master/samples/SoftKeyboard
的Android自定义键盘他们在res / xml文件夹下有qwerty和symbols键盘。我添加了一个虚拟键盘(friendlist.xml),如下所示:
<?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>
我需要以编程方式将“Key”添加到此键盘(friendlist.xml)中。 在SoftKeyboard.java中,
我添加了以下内容:
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);
}
但我找不到任何可以在运行时将Row和Key添加到键盘中的函数。
请欣赏任何帮助。谢谢!
Cheerio, Mark Thien
答案 0 :(得分:0)
还有一个额外的构造函数,它作为参数键添加到键盘。它仅限于字符。
public Keyboard(Context context, int layoutTemplateResId,
CharSequence characters, int columns, int horizontalPadding);
仅包含人声的动态键盘示例:
mFriendlistKeyboard = new Keyboard(this, R.xml.friendlist, 'AEIOU', -1, 0);
如果您需要的不仅仅是“字符”键,那么扩展键盘将是必要的。