@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);

}

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐