Android的自定义键盘颜色,android自定义键盘与更改单个Keys的背景色
@Overridepublic void onDraw(Canvas canvas) {// super.onDraw(canvas);Listkeys = getKeyboard().getKeys();for (Key key : keys) {if (key.codes[0] == 7) {NinePatchDrawable npd= (NinePatchDrawable) context.
@Override
public void onDraw(Canvas canvas) {
// super.onDraw(canvas);
Listkeys = getKeyboard().getKeys();
for (Key key : keys) {
if (key.codes[0] == 7) {
NinePatchDrawable npd
= (NinePatchDrawable) context.getResources().getDrawable(R.drawable.red_key);
npd.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
npd.draw(canvas);
} else {
NinePatchDrawable npd
= (NinePatchDrawable) context.getResources().getDrawable(R.drawable.blue_key);
npd.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
npd.draw(canvas);
}
Paint paint = new Paint();
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(48);
paint.setColor(Color.GRAY);
if (key.label != null) {
canvas.drawText(key.label.toString(), key.x + (key.width / 2),
key.y + (key.height / 2), paint);
} else {
key.icon.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
key.icon.draw(canvas);
}
}
}
更多推荐
所有评论(0)