如何在自定义Android键盘中更改KeyboardView类中键的颜色?
我正在开发一个自定义键盘应用程序。我需要在KeyboardView类中为键或背景色设置不同的主题,并在SoftKeyboard extends InputMethodService类的onCreateInputView()中获取键颜色如何在自定义Android键盘中更改KeyboardView类中键的颜色?,android,android-softkeyboard,Android,Android Softkeyboard,我正在开发一个自定义键盘应用程序。我需要在KeyboardView类中为键或背景色设置不同的主题,并在SoftKeyboard extends InputMethodService类的onCreateInputView()中获取键颜色 但是,我不知道如何根据keycode获取特定的键,以便我可以更改特定键的颜色或背景。在任何不同的输入布局上使用android:keyBackground=“…” 例如: input.xml: <com.example.KeyboardView
但是,我不知道如何根据keycode获取特定的键,以便我可以更改特定键的颜色或背景。在任何不同的输入布局上使用android:keyBackground=“…” 例如: input.xml:
<com.example.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:keyBackground="@drawable/blue_key"
/>
在方法onStartInput的末尾添加以下内容:
setInputView(onCreateInputView());
如果你已经这样做了,你需要的是设置一个不同的背景特殊关键点。也许我写的问题解决方案会帮助你:
祝你好运!:) 到目前为止你试过什么?提供您尝试过的代码将帮助您获得帮助。我已设置为input.xml和input1.xml我需要在运行时获取keycode,即不同的键颜色我使用了三个input.xml、input1.xml、input2.xml如果input.xml膨胀,则keycolor将为绿色,蓝色组合如果input1.xml充气键,背景颜色将为红色和橙色。与input2.xml类似,因此我不知道如何使用。此外,背景不必是可绘制的。它也可以是颜色资源。此代码用于更改键盘背景的颜色,而不是keyboardtextcolor。是否以编程方式更改颜色
@Override public View onCreateInputView() {
if(theme == 1)
mInputView = (KeyboardView) getLayoutInflater().inflate(R.xml.input , null);
else
mInputView = (KeyboardView) getLayoutInflater().inflate(R.xml.input1 , null);
mInputView.setOnKeyboardActionListener( this);
mInputView.setKeyboard(mQwertyKeyboard);
mComposing.setLength(0);
return mInputView;
}
setInputView(onCreateInputView());