How can I change the background image of a field manager while focus change in BlackBerry Java
Asked Answered
T

1

15

I'm a newbie to blackberry and creating menu with options. Each option contains a bitmap image and label.

This is the code for the first menu item:

hmf1_vfm1 = new VerticalFieldManager(Field.FIELD_HCENTER |          VErrticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.FIELD_HCENTER |   VerticalFieldManager.FOCUSABLE | Field.FOCUSABLE)
{
 boolean isFocus;
//Bitmap bmp1 = Bitmap.getBitmapResource("mnu_tile1.png");
protected void sublayout(int maxWidth, int maxHeight)
 {
super.sublayout(100,125);
setExtent(100,125);
 }

protected void paint(Graphics g) {
try
{
   //g.setBackgroundColor(0x504A4B);
   //g.drawBitmap(0, 0, bmp1.getWidth(), bmp1.getHeight(), bmp1, 0, 0);
                    g.clear();
    Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("mnu_tile1.png")); //mnu_tile1.png
                    this.setBackground(bg);
                    super.paint(g);
                }
                catch (IllegalArgumentException e) {
                    //SupportClass.showLog(TAG+" err 2 : "+e);
                }
            }

            protected void onFocus(int direction) {
                isFocus = true;
                super.onFocus(direction);
            }
            protected void onUnfocus() {
                isFocus = false;
                super.onUnfocus();
            }

            protected boolean navigationClick(int status, int time) {

                //SupportClass.showLog("New Order...navigationClick");
                return true;
            }
            public boolean isFocusable() {
                return true;
            }
            /*protected boolean touchEvent(net.rim.device.api.ui.TouchEvent message) {

                //SupportClass.showLog("New Order...touchEvent");
                return true;
            };*/
        };

The bitmap & label fields are added to this vfm. by the way as

BitmapField bfNO = new BitmapField(bmpNO,Field.FIELD_HCENTER | Field.FOCUSABLE)
        {
            protected boolean navigationClick(int status, int time) {
                SupportClass.showLog("bitmap...navigationClick");
                return true;
            }
            protected void paint(Graphics graphics) {
                //this.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK,0));
                super.paint(graphics);
            }
        };

LabelField txtNO = new LabelField("New Order",LabelField.FIELD_HCENTER | Field.FOCUSABLE )
        {
            protected void paint(Graphics g) {
                g.setColor(Color.WHITE);
                //g.setBackgroundColor(0x00000000);
                super.paint(g);
            }
            protected boolean navigationClick(int status, int time) {
                SupportClass.showLog("lable...navigationClick");
                return true;
            }
        };
  • I want to focus the vertical field manager which containing the image & label, while setting the background I can't see the background. I guess some layer is overlapped on the background.

  • Also I want to change the selector color of the fields (blue background) into transparent.

  • Please tell me what mistake I'm making.

Tiltyard answered 16/1, 2013 at 9:52 Comment(2)
did you check the PictureBackgroundButtonField.java of here...! #8942725Praetor
This was asked over a year ago. If the OP is still interested in a response, please update the question and I will provide some assistance. Otherwise there appears to be no value answering this as the code is specific and I suspect the general points that could be made to this have already been covered in other, better questions.Lonni
V
0

Hi Please try with invalidate() method.

Valleau answered 9/4, 2014 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.