- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作自定义键盘,但它没有输出我在 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/
keyOutputText 在软键盘上不起作用。 > > > > 如上,但它不会向压力按钮写入任何内容。 最佳答案 我找到了解决
您好,我正在开发一个自定义键盘,我在键盘 xml 中使用了 android:keyOutputText=""。如何在java类中获取该文本?我只找到了如何使用 android:codes 与十进制代码
我正在尝试制作自定义键盘,但它没有输出我在 Key 节点上的 keyOutputText 中设置的文本值。 这是activity_main.xml: 这是键盘布局:
我正在尝试修改 SoftKeyboard 示例(Moto Xoom 上的 Andriod 3.1),以便我可以在键上使用图标并让它输出 unicode 字符该键被按下。 具体来说,我试图让它输出一个八
我是一名优秀的程序员,十分优秀!