我已经遵循this tutorial并创建了自己的键盘,但是无法更改其键的背景颜色。
keyboard.xml
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:horizontalGap="3px"
android:keyWidth="10%p"
android:keyHeight="60dp"
android:keyBackground="@color/color_green"
android:keyTextColor="@color/color_red"
android:verticalGap="3px">
keyboard_view.xml
<android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/all_white">
</android.inputmethodservice.KeyboardView>
MyInputMethodService.java
@Override
public View onCreateInputView() {
keyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard_view, null);
keyboardView.setPreviewEnabled(false);
keyboard = new Keyboard(this, R.xml.number_pad);
keyboardView.setKeyboard(keyboard);
keyboardView.setOnKeyboardActionListener(this);
return keyboardView;
}
我曾尝试更改android:keyBackground
和android:keyTextColor
,但没有任何变化,但是如果我在同一文件中更改某些键值,它将起作用。