在黑莓的标题中设置背景图像?

时间:2012-07-09 07:47:46

标签: blackberry

我想添加header.In标题,我想在Blackberry中添加背景图像和两个按钮.. 所以我必须做什么?

我试过以下......但它没有用..

VerticalFieldManager vfm=new VerticalFieldManager();
        vfm.setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("topbar.png")));
        setTitle(vfm);

2 个答案:

答案 0 :(得分:1)

试试这个 -

    final Bitmap bg = Bitmap.getBitmapResource("bg.png");
       VerticalFieldManager vfm_mid = new VerticalFieldManager(Manager.NO_HORIZONTAL_SCROLL | Manager.NO_HORIZONTAL_SCROLLBAR | Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | Field.USE_ALL_WIDTH){

            public void paint(Graphics graphics) {
                graphics.setBackgroundColor(0x040811);
                graphics.clear();
                graphics.drawBitmap(0, 0, bg.getWidth(),
                        bg.getHeight(), bg, 0, 0);
                super.paint(graphics);
            }

        };




    ButtonField b1=new ButtonField("Button 1");
    ButtonField b2=new ButtonField("Button 2");
    vfm_mid.add(b1);
    vfm_mid.add(b2);

    setTitle(vfm_mid);

答案 1 :(得分:0)

尝试此自定义标题:

public class TopBar extends HorizontalFieldManager implements FieldChangeListener{

 int width;
 int height;
 Bitmap bgBitmap;
 Button btnHome; 
 Bitmap btnImage;
 boolean isHome;
 MainScreen screenFromNavigate;
LabelField lblTitle;


    public TopBar(String title)
    {
        super(FIELD_HCENTER);
        setLayout(title);

    }

    public void setLayout(String title)
    {
        this.width=Display.getWidth();
        this.height=50;
        this.bgBitmap= Bitmap.getBitmapResource("topbar.png");
        this.isHome = isHomeBtn;


            btnHome = new ButtonField("Button 1");
            btnHome.setMargin(7, 0, 0, 15);

        add(btnHome);
        btnHome.setChangeListener(this);

        lblTitle = new LabelField(title);

        add(lblTitle);
        lblTitle.setMargin(12, 0, 0,Display.getWidth()/2-160);


    }

    protected void sublayout(int maxWidth, int maxHeight)
    {
        maxWidth=width;
        maxHeight=height;
        super.sublayout(maxWidth, maxHeight);
        setExtent(maxWidth, maxHeight);
    }
    protected void paint(Graphics graphics)
    {
        graphics.drawBitmap(0, 0, Display.getWidth(),50, bgBitmap, 0, 0);
        // graphics.setBackgroundColor(Color.GRAY);
        // graphics.clear();

        super.paint(graphics);
    }

    public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub
        }

    }
 }

打电话给:

TopBar topBar = new TopBar(“Test”);

的setTitle(顶栏);