软键盘的弹出式布局 [英] Soft keyboard's POPUP layout
问题描述
我正在开发一个软键盘和做的很好,但我不知道如何自定义弹出布局相当长的关键preSS。
I'm developing a soft keyboard and doing well, but I don't know how to customize the popup layout for a long keypress.
<?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"
android:keyPreviewLayout="@layout/preview"
android:keyBackground="@drawable/key_selector"
android:shadowRadius="0.0"
android:keyTextColor="#000000"
/>
我的键盘布局:
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:keyHeight="10%p">
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p">
<Key android:codes="113" android:keyLabel="q" />
<Key android:codes="119" android:keyLabel="w" />
<Key android:codes="101" android:keyLabel="e"
/>
<Key android:codes="114" android:keyLabel="r" />
<Key android:codes="116" android:keyLabel="t" />
<Key android:codes="121" android:keyLabel="y"
android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="yýÿ"/>
<Key android:codes="117" android:keyLabel="u"
android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="uúùũûü"/>
<Key android:codes="105" android:keyLabel="i"
android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="iíìĩîï"/>
<Key android:codes="111" android:keyLabel="o"
android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="oóòõôö" />
<Key android:codes="112" android:keyLabel="p" />
</Row>
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p">
<Key android:codes="97" android:keyLabel="a" android:keyEdgeFlags="left" android:horizontalGap="5%p"
android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="aáàãâä"/>
<Key android:codes="115" android:keyLabel="s" />
<Key android:codes="100" android:keyLabel="d" />
<Key android:codes="102" android:keyLabel="f" />
<Key android:codes="103" android:keyLabel="g" />
<Key android:codes="104" android:keyLabel="h" />
<Key android:codes="106" android:keyLabel="j" />
<Key android:codes="107" android:keyLabel="k" />
<Key android:codes="108" android:keyLabel="l" />
</Row>
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p">
<Key android:codes="3" android:keyIcon="@drawable/keyboard_shift_off"
android:keyHeight="7.6%p" android:keyWidth="13.7%p"/>
<Key android:codes="122" android:keyLabel="z" android:horizontalGap="1%p"/>
<Key android:codes="120" android:keyLabel="x" />
<Key android:codes="99" android:keyLabel="c"
android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="cç"/>
<Key android:codes="118" android:keyLabel="v" />
<Key android:codes="98" android:keyLabel="b" />
<Key android:codes="110" android:keyLabel="n"
android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="nñ"/>
<Key android:codes="109" android:keyLabel="m" />
<Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete_dim"
android:keyHeight="7.6%p" android:keyWidth="13.7%p"
android:horizontalGap="1%p"/>
</Row>
<Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p">
<Key android:codes="-16" android:keyIcon="@drawable/keyboard_symbol"
android:keyHeight="7.6%p" android:keyWidth="18.7%p"/>
<Key android:codes="44" android:keyLabel="," android:horizontalGap="1%p"/>
<Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_feedback_space" android:keyWidth="40%p"/>
<Key android:codes="46" android:keyLabel="."/>
<Key android:codes="-3" android:keyIcon="@drawable/keyboard_go"
android:keyHeight="7.6%p" android:keyWidth="18.5%p" android:horizontalGap="1%p"/>
</Row>
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:keyHeight="10%p">
</Keyboard>
我试图把的 keyBackground 的和的背景属性的无处不在,但没有成功。我试图把:
I tried putting keyBackground and background properties everywhere, but not successfully. I tried to put:
android:popupLayout="@layout/keyboard"
...在的 keyboardView 的却得到空指针,也许我把一个错误的XML在参数?
...On the keyboardView but get nullpointer, maybe I'm putting a wrong XML in that parameter?
在键盘弹出的XML,我把这里:
In the keyboard popup XML that I put here:
android:popupKeyboard="@xml/keyboard_popup"
我可以改变布局的大小,键大小,按键缝隙,和其他的东西,但不能改变颜色或背景。
I can change the layout's size, key size, key gap, and other things, but can't change the colors or backgrounds.
的键preVIEW 的也做得很好,我把这个上的 keyboardView 的:
The key preview also is doing well, I put this on the keyboardView:
android:keyPreviewLayout="@layout/preview"
...和它的作品。我认为,在弹出的应该是相同的方式,但它不是。
...And it works. I think the popup should be the same way, but it's not.
推荐答案
嗯,这不正是我一直在寻找,但这个解决该问题。
Well, it is not exactly what I was looking for, but this resolves the problem.
我做我自己的键盘看法,并提出一个弹出窗口,显示当一个密钥为pressed。
I made my own keyboard view and made a popup window to show when a key is long pressed.
public class MyKeyboardView extends KeyboardView{
@Override
protected boolean onLongPress(final Key popupKey) {
final View custom = LayoutInflater.from(context)
.inflate(R.layout.popup_layout, new FrameLayout(context));
popup = new PopupWindow(context);
popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.showAtLocation(this, Gravity.NO_GRAVITY, popupKey.x, popupKey.y-50);
}
}
此方式,您可以自定义弹出您在XML想要的任何方式。
This way you can customize the popup any way you want in the xml.
这篇关于软键盘的弹出式布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!