Android InputMethodEditor布局文件.XML中的非键/行元素? [英] Android InputMethodEditor layout file. Non-Key/Row elements in the XML?
本文介绍了Android InputMethodEditor布局文件.XML中的非键/行元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试实现一个TextView键盘,该键盘会随着每次按键的更新而更新,但不会显示在屏幕上.它应该出现在字母的第一行上方.
I'm trying to implement a keyboard with a TextView that updates with each keypress, but it won't show up on the screen. It should appear above the top row of letters.
当我运行键盘时,按键会显示在顶部,但里面没有一行
When I run the keyboard, the keys show up with an extra row on top but nothing inside
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:id="@+id/keyboardView"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="60dp"
>
<Row>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="fill_parent"
android:text="@string/text_view_default"
android:visibility="visible"/>
<!--android:layout_height="50dp"-->
</Row>
<Row>
<Key android:codes="49" android:keyLabel="1" android:keyEdgeFlags="left"/>
<Key android:codes="50" android:keyLabel="2"/>
<Key android:codes="51" android:keyLabel="3"/>
<Key android:codes="52" android:keyLabel="4"/>
<Key android:codes="53" android:keyLabel="5"/>
<Key android:codes="54" android:keyLabel="6"/>
<Key android:codes="55" android:keyLabel="7"/>
<Key android:codes="56" android:keyLabel="8"/>
<Key android:codes="57" android:keyLabel="9"/>
<Key android:codes="48" android:keyLabel="0" android:keyEdgeFlags="right"/>
</Row>
.
.
.
</Keyboard>
推荐答案
您将不得不更改键盘布局以包含您的 TextView
和 KeyboardView
.
You will have to change your keyboard layout to contain your TextView
and KeyboardView
.
1)如下更改IME布局:
1) change IME layout as below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/tvKeyboard"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center"
android:padding="10dp"
android:scaleType="fitEnd"
android:src="@drawable/keyboard_icon" />
</RelativeLayout>
<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"
android:keyPreviewLayout ="@layout/preview"
/>
</LinearLayout>
2)在您的IME类中进行一些更改:
2) In your IME class make a few changes:
@Override
public View onCreateInputView() {
final View root = getLayoutInflater().inflate(R.layout.idee_keyboard_layout, null);
TextView tvKeyboard = (TextView) root.findViewById(R.id.tvRevertKeyboard);
tvKeyboard.setText("set your text here");
kv = (KeyboardView) root.findViewById(R.id.keyboard);
keyboard = new Keyboard(this, R.xml.qwerty);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
return root;
}
完成.
这篇关于Android InputMethodEditor布局文件.XML中的非键/行元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文