Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to make a screen like this: enter image description here 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.

like image 449
Lucas Avatar asked Dec 13 '25 11:12

Lucas


1 Answers

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);

enter image description here

like image 200
tonymontana Avatar answered Dec 15 '25 23:12

tonymontana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!