我正在尝试更改 Android 中的键盘视图键颜色。键颜色已更改。但文本在键中不可见。
@Override
public void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
List<Keyboard.Key> keys = getKeyboard().getKeys();
for (Keyboard.Key key : keys) {
if (key.codes[0] == 53) {
Drawable dr = context.getResources().getDrawable(R.drawable.samplekeybackground);
dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
dr.draw(canvas);
}
}
}
示例keybackground.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item
android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/normal" />
<!-- Pressed state -->
<item
android:state_pressed="true"
android:drawable="@drawable/pressed" /></selector>
正常的.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dp" android:color="#00FFFFFF" />
<solid android:color="#AABBCC" />
<corners
android:radius="5dp"/>
</shape>
按下的.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="5dp" android:color="#000000" />
<solid android:color="#CCBBAA"/>
<corners
android:radius="5dp"/>
</shape>
请让我有一些想法来解决这个问题。