gpt4 book ai didi

android - 定制键盘

转载 作者:行者123 更新时间:2023-11-29 18:22:25 24 4
gpt4 key购买 nike

我是开发 Android 应用程序的新手,我正面临一个难度。

我想做的是当我点击一个特定的键盘时使用特定的键盘编辑文本。到目前为止,我已经找到了 KeyboardKeyboardView类,但我还没有成功地做我想做的事。

这是我所在位置的描述:

  • 我已经在 XML 文件中描述了我的键盘,
  • 我创建了一个“KeyboardView”对象,
  • 我用 clavier=new KeyboardView(activité,
    (AttributeSet)findViewById(R.xml.clavier_numerique));
  • 但我不知道如何用这个替换标准键盘自定义键盘。

我做错了什么吗?我还应该做什么?

在此先感谢您花时间帮助我。

最佳答案

你应该使用这样的东西:

    //retrieve the keyboard view from xml
kbdV= (KeyboardView) findViewById(R.id.kbd);

//set the keyboard layout to the layout you defined in res/xml/keyboard_layout.xml
kbdV.setKeyboard(new Keyboard(this,R.xml.keyboard_layout)); //defines the keyboard layout

//add a keyboard action listener
kbdV.setOnKeyboardActionListener(new KeyboardView.OnKeyboardActionListener(){
public void onKey(int primaryCode, int[] keyCodes) {
handlePress(primaryCode, keyCodes); // callback to handle keypresses
}
public void onPress(int primaryCode) {}
public void onRelease(int primaryCode) {}
public void onText(CharSequence text) {}
public void swipeDown() {}
public void swipeLeft() {}
public void swipeRight() {}
public void swipeUp() {}
});

使用与此类似的布局 xml 文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<!-- your widgets here -->

<KeyboardView android:id="@+id/kbd" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>

关于android - 定制键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4692345/

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