2

I have tried it overriding paint() method inside my own class which extends LabelField, but I ignore if there is another simpler way.

My code:

protected void paint(Graphics graphics) {
    int previousColor = graphics.getColor();
    graphics.setColor(0xFFFFFF);
    graphics.drawText(getText(), 2, -2);
    graphics.setColor(previousColor);
    super.paint(graphics);
}

What I want to achieve is this:

enter image description here

EDIT: The answer by Abhisek produces the following result, in case anyone is interested:

enter image description here

4

2 回答 2

3

如果Abhishek 的回答不起作用,您可以尝试直接在paint方法中进行操作。这很简单,只需以 bg 颜色绘制一次,然后以 fg 颜色在其上再次绘制(向下几个像素并离开之前的文本)。像这样的东西:

    protected void paint(Graphics graphics) {
        graphics.setColor(0xFFFFFF);
        graphics.drawText(getText(), 2, 0);
        graphics.setColor(0x000000);
        graphics.drawText(getText(), 0, 2);
    }

请注意您需要 2 个额外的高度和宽度像素,因此您可能必须覆盖getPreferredWidth,getPreferredHeight和/或layout.

于 2012-12-14T12:26:21.463 回答
0

在黑暗中刺伤,但尝试使用 派生字体Font.derive(style, height, units, aAntialiasMode, aEffects),传入参数并将其应用于相关字段Font.DROP_SHADOW_RIGHT_EFFECTaEffects

请告诉我们它是否有效;我没有使用它,因为它没有记录!

于 2012-12-14T12:08:25.947 回答