简体   繁体   中英

BlackBerry - How to put a background image behind a button?

I need to make a screen like this:在此处输入图片说明 The only thing I need to add to my code is something to put the background image behind those buttons.

This is what I have so far:

public class PruebaScreen extends MainScreen{
    public PruebaScreen(){
         LabelField title = new LabelField("Screen Title");
         title.setPadding(40, 0, 20, 60);

         BitmapField btn1 = new BitmapField(Bitmap.getBitmapResource("btn-1.png"));
         btn1.setPadding(2,0,3,0);

         BitmapField btn2 = new BitmapField(Bitmap.getBitmapResource("btn-2.png"));
         btn2.setPadding(2,0,3,0);

         add(title);
         add(btn1);
         add(btn2);

    }
}

How should I do to put those two buttons over the background image?. The image should not take all the screen.

Thanks in advance.

You should

  1. Create a manager ( VericalFieldManager )
  2. Set the desired background for the manager
  3. Add the buttons to the manager
  4. Add the manager to the screen

Here is a code snippet that creates a solid color background :

    LabelField title = new LabelField("Screen Title");
    title.setPadding(40, 0, 20, 60);

    VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH);
    vfm.setBackground(BackgroundFactory.createSolidBackground(Color.BLUE));
    vfm.setPadding(20, 0, 20, 0);

    ButtonField btn1 = new ButtonField("Option 1");
    btn1.setPadding(2, 0, 3, 0);

    ButtonField btn2 = new ButtonField("Option 2");
    btn2.setPadding(2, 0, 3, 0);

    add(title);
    vfm.add(btn1);
    vfm.add(btn2);
    add(vfm);

To make the background a bitmap, just replace

    vfm.setBackground(BackgroundFactory.createSolidBackground(Color.BLUE));

with

    vfm.setBackground(BackgroundFactory.createBitmapBackground(YOUR BITMAP);

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM