gpt4 book ai didi

android - 动态更改键盘布局

转载 作者:太空宇宙 更新时间:2023-11-03 11:51:12 24 4
gpt4 key购买 nike

我正在创建自定义键盘。我从 Here 得到了一个非常有用的演示。 .我想创建多个键盘主题,所以我为键盘创建了另一个布局,但现在的问题是我不知道如何设置当前键盘的布局或者必须重新加载键盘或者必须做其他事情..来改变键盘的设计没有任何想法。

我的想法是用户必须从 Activity 中选择键盘主题,键盘设计将会改变。

任何人都可以帮助我或有任何想法来解决这个问题..?

最佳答案

获取更改自定义键盘布局的解决方案。

当键盘第一次加载时调用 onCreateInputView()。之后每次打开键盘时都会调用 onStartInputView(EditorInfo attribute, boolean restarting)。

所以,现在键盘(主题)的布局必须像这样在 onCreateInputView() 中定义

public KeyboardView mInputView;
public View onCreateInputView() {

SharedPreferences pre = getSharedPreferences("test", 1);
int theme = pre.getInt("theme", 1);

if(theme == 1)
{
this.mInputView = (KeyboardView) this.getLayoutInflater().inflate(R.layout.input, null);
}else
{
this.mInputView = (KeyboardView) this.getLayoutInflater().inflate(R.layout.input_2, null);

}
this.mInputView.setOnKeyboardActionListener(this);
this.mInputView.setKeyboard(this.mQwertyKeyboard);
return this.mInputView;
}

并在 onStartInputView 中执行此操作

public void onStartInputView(EditorInfo attribute, boolean restarting) {
super.onStartInputView(attribute, restarting);

setInputView(onCreateInputView());
}

关于android - 动态更改键盘布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14190289/

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