gpt4 book ai didi

Android自定义软键盘——设置键盘宽度为match_parent(设备屏幕宽度)

转载 作者:太空狗 更新时间:2023-10-29 14:53:49 31 4
gpt4 key购买 nike

我想要一个像图 2 那样多一些按钮的软键盘。

我正在关注这个例子: https://android.googlesource.com/platform/development/+/master/samples/SoftKeyboard/

但我的问题是我不知道如何通过设置 keyWidth 15% 来设置软键盘宽度以匹配其父键盘 -> 我的键盘左侧是空的,如图 1 所示。

你能帮帮我吗?谢谢,

类软键盘

public class SoftKeyboard extends InputMethodService 
implements KeyboardView.OnKeyboardActionListener {

private LatinKeyboardView mInputView; //public class LatinKeyboardView extends KeyboardView

@Override public View onCreateInputView() {
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
R.layout.input, null);
mInputView.setOnKeyboardActionListener(this);
setLatinKeyboard(mQwertyKeyboard);
return mInputView;
}


@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);
mNumberKeyboard = new LatinKeyboard(this, R.xml.number);
}

//...
}

R.layout.input.xml:

    android:id="@+id/keyboard"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"

R.xml.number.xml:

<Keyboard
android:keyWidth="15%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="@dimen/key_height"
android:layout_width="match_parent">

<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="-5" android:keyIcon="@drawable/sym_keyboard_delete" android:keyEdgeFlags="right"
android:isRepeatable="true"/>
</Row>

<Row>
<Key android:codes="52" android:keyLabel="4" android:keyEdgeFlags="left"/>
<Key android:codes="53" android:keyLabel="5"/>
<Key android:codes="54" android:keyLabel="6"/>
<Key android:codes="28" android:keyLabel="RAZ" android:keyEdgeFlags="right"/>
</Row>

<Row>
<Key android:codes="55" android:keyLabel="7" android:keyEdgeFlags="left"/>
<Key android:codes="56" android:keyLabel="8"/>
<Key android:codes="57" android:keyLabel="9" android:keyEdgeFlags="right" />
</Row>

<Row android:rowEdgeFlags="bottom">
<Key android:codes="-3" android:keyIcon="@drawable/sym_keyboard_done" />
<Key android:codes="48" android:keyLabel="0"/>
<Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
android:keyWidth="47%p" android:keyEdgeFlags="right"/>
</Row>
</Keyboard>

enter image description here

enter image description here

最佳答案

在这里改变你的xml

<?xml version="1.0" encoding="utf-8"?>

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="20%p"
android:horizontalGap="6%p"
android:verticalGap="2.15%p"
android:keyHeight="@dimen/key_height"
>

图片

proper work

谢谢

关于Android自定义软键盘——设置键盘宽度为match_parent(设备屏幕宽度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33077300/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com