1

我想添加标题。在标题中,我想在黑莓中添加背景图像..和两个按钮..。那我该怎么办??

我试过关注..但它没有用..

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

2 回答 2

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);
于 2012-07-09T07:51:53.123 回答
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");

设置标题(顶栏);

于 2012-07-09T11:08:41.553 回答