我正在使用 TabLayout 来显示不同的输入法。第一个选项卡包含按钮,第四个选项卡应显示嵌入此 TabLayout 中的标准键盘。这是它应该是什么样子的截图:
到目前为止,TabLayout 可以正常工作。我试图用 KeyboardView 创建一个布局 XML 文件。但是应用程序没有显示键盘:
<?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"
/>
如果我使用的是简单的 Textview,应用程序会显示文本...因此 TabLayout 本身可以正常工作:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="This is a tab layout"
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
我的问题是如何创建一个简单的键盘并在 TabLayout 中显示它?谢谢!
最佳答案
大约两年前我写了一个 IME。你的情况和我的不一样,但思路应该是一样的。
问题是您没有为键盘 View 指定键盘布局。
查看代码:
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Round up a little
if (mKeyboard == null) {
setMeasuredDimension(mPaddingLeft + mPaddingRight, mPaddingTop + mPaddingBottom);
} else {
int width = mKeyboard.getMinWidth() + mPaddingLeft + mPaddingRight;
if (MeasureSpec.getSize(widthMeasureSpec) < width + 10) {
width = MeasureSpec.getSize(widthMeasureSpec);
}
setMeasuredDimension(width, mKeyboard.getHeight() + mPaddingTop + mPaddingBottom);
}
}
mKeyboard
变量可以通过setKeyboard
设置。你应该做的是:
- 在资源文件夹中创建键盘布局文件
- 创建一个
Keyboard
实例并将其设置为KeyboardView
- 尝试运行代码。
关于android - 在 android TabLayout 中显示虚拟键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38326894/