【问题标题】:Custom buttons aren't displaying on my UI自定义按钮未显示在我的 UI 上
【发布时间】:2010-09-09 23:30:38
【问题描述】:

我正在为测试目的创建一个简单的黑莓应用程序,但我的自定义按钮未显示在模拟器的 UI 上。

我创建了一个名为 CustomButtonField 的自定义按钮,代码如下:

package test.expense;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

public class CustomButtonField extends Field {
    String label;
    int backgroundColor;
    int foregroundColor;

    public CustomButtonField(String label, int backgroundColor, int foregroundColor, long style){
        super(style);
        this.label = label;
        this.backgroundColor = backgroundColor;
        this.foregroundColor = foregroundColor;
    }

    public int getPreferedHeight(){
        return getFont().getHeight() + 8;
    }

    public int getPreferedWidth(){
        return getFont().getAdvance(label) + 8;
    }

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

    protected void paint(Graphics graphics) {
        graphics.setColor(backgroundColor);
        graphics.fillRoundRect(1, 1, getWidth()-2, getHeight()-2, 12, 12);
        graphics.setColor(foregroundColor);
        graphics.drawText(label, 4, 4);
    }

}

这里是我调用它并显示它的地方:

HorizontalFieldManager buttonManager = new HorizontalFieldManager(FIELD_RIGHT);
CustomButtonField btnCancel;
CustomButtonField btnSubmit;

public ExpenseSheetScreen() {
    super();
        btnCancel = new CustomButtonField("Cancel", Color.WHITE, 0x716eb3, 0);
    btnCancel.setChangeListener(this);
    btnSubmit = new CustomButtonField("Submit", Color.WHITE, 0x716eb3, 0);
    btnSubmit.setChangeListener(this);

    buttonManager.add(btnCancel);
    buttonManager.add(btnSubmit);

    add(buttonManager);
}// End Expense Sheet Screen.

我做错了什么?

【问题讨论】:

    标签: user-interface blackberry custom-controls


    【解决方案1】:
     protected void layout(int width, int height) {
        setExtent(Math.min(width, getPreferredWidth()), 
        Math.min(height, getPreferredHeight()));
     }
    

    setExtend 一直设置为 0、0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      • 2012-05-10
      • 2014-03-09
      • 2023-03-09
      相关资源
      最近更新 更多