【问题标题】:how to create widget in blackberry?如何在黑莓中创建小部件?
【发布时间】:2013-10-16 19:48:33
【问题描述】:

这是我的自定义布局,与 android linear layout 相同

public class Custom_TopField extends VerticalFieldManager {
    private static final int FIELD_HEIGHT = 70;

    private String _text;

    Custom_TopField(int color, String text) {
        super(Manager.NO_VERTICAL_SCROLL);
        _text = text;

        Background background = BackgroundFactory.createSolidBackground(color);
        setBackground(background);
    }

    protected void sublayout(int width, int height) {
        width = Math.min(width, getPreferredWidth());
        height = Math.min(height, getPreferredHeight());
        setExtent(width, height);
    }

    public int getPreferredHeight() {
        return FIELD_HEIGHT;
    }

    public int getPreferredWidth() {
        return Display.getWidth();
    }

    public void paint(Graphics graphics) {
        int rectHeight = getPreferredHeight();
        int rectWidth = getPreferredWidth();

        Font font = Font.getDefault().derive(Font.BOLD, 65);
        graphics.drawRect(0, 0, rectWidth, rectHeight);
        graphics.drawText(_text, rectWidth / 2, 10);
        graphics.setFont(font);
        graphics.setColor(Color.WHITE);
        super.paint(graphics);
    }
}

输出 = 背景红色,字体 = 黑色

我想要的是背景红色,字体白色,字体大小 40。

我也想知道如何以编程方式创建小部件?

【问题讨论】:

    标签: blackberry widget field


    【解决方案1】:

    要将字体设置为白色并将大小设置为 40,请按如下方式更改绘制:

    public void paint(Graphics graphics) {
        int rectHeight = getPreferredHeight();
        int rectWidth = getPreferredWidth();
    
        Font font = Font.getDefault().derive(Font.BOLD, 40);
        graphics.setColor(Color.WHITE);
        graphics.setFont(font);
        graphics.drawRect(0, 0, rectWidth, rectHeight);
        graphics.drawText(_text, rectWidth / 2, 10);
        super.paint(graphics);
    }
    

    【讨论】:

    • 知道了。在黑莓中创建一个 textview(android) 怎么样?
    • textview 是什么意思?
    • android 中的 textview 小部件是静态文本,我想在黑莓中调用
    • 检查 RichTextField ...是你想要的吗?
    • 是的,其他的怎么样,比如edittext等...或者有教程或例子?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    相关资源
    最近更新 更多