gpt4 book ai didi

java - 自定义 KeyboardView 上的 keyOutputText 属性不输出任何文本

转载 作者:行者123 更新时间:2023-12-01 10:28:08 28 4
gpt4 key购买 nike

我正在尝试制作自定义键盘,但它没有输出我在 Key 节点上的 keyOutputText 中设置的文本值。

这是activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />

<EditText
android:layout_width="match_parent"
android:layout_height="match_parent" />

</RelativeLayout>

这是键盘布局:

<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="0px"
android:keyHeight="60dp"
android:keyWidth="15%p"
android:verticalGap="0px">

<Row>
<Key
android:keyLabel="test"
android:keyOutputText="test" />
</Row>
</Keyboard>

这是 Java 类:

import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.view.View;
import android.view.inputmethod.InputConnection;

public class TestKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener {

private KeyboardView kv;
private Keyboard keyboard;

@Override
public View onCreateInputView() {
kv = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.keyboard);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
return kv;
}

@Override
public void onPress(int primaryCode) {
}

@Override
public void onRelease(int primaryCode) {
}

@Override
public void onKey(int primaryCode, int[] keyCodes) {
}

@Override
public void onText(CharSequence text) {

}

@Override
public void swipeLeft() {

}

@Override
public void swipeRight() {

}

@Override
public void swipeDown() {

}

@Override
public void swipeUp() {

}
}

我还没有真正找到任何关于这方面的优秀教程,所以我不确定我是否还没有实现任何我应该实现的代码?如有必要,我将提供更多代码和资源。一切正常,应用程序构建并启动,我可以将当​​前的键盘设置为这个键盘,但当我实际按下该键时没有任何反应。它的响应就像我按下它一样,但没有输出任何文本。

最佳答案

事实证明,我只需要实现 onText 方法即可。

@Override
public void onText(CharSequence text) {
getCurrentInputConnection().commitText(text, 1);
}

关于java - 自定义 KeyboardView 上的 keyOutputText 属性不输出任何文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35248123/

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