我正在创建自定义键盘。我从这里得到了一个非常好的、有用的演示。我想创建多个主题的键盘,所以我为键盘创建了另一个布局,但现在的问题是我不知道如何设置当前键盘的布局,或者必须重新加载键盘,或者必须进行其他操作,来改变键盘的设计,我没有任何想法。
我的思路是用户可以从活动中选择键盘主题,然后键盘设计会更改。
有人可以帮助我或者有任何想法来解决这个问题吗?
我的思路是用户可以从活动中选择键盘主题,然后键盘设计会更改。
有人可以帮助我或者有任何想法来解决这个问题吗?
获得更改自定义键盘布局的解决方案。
当键盘初次加载 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());
}