如何在黑莓中制作状态栏?

发布于 2025-01-01 11:29:49 字数 1561 浏览 1 评论 0原文

我想在屏幕底部设置状态栏,它应该在左侧和右侧显示一个按钮。你可以在下面看到我的屏幕。 我的代码是这样的..

private void BottomLayout() 
    {
        Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
        final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
        HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
        {
            protected void paintBackground(Graphics graphics) 
            {
                graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );             
                super.paint(graphics);
            }
            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                super.sublayout(topBg1.getWidth(), topBg1.getHeight());
                setExtent(topBg1.getWidth(), topBg1.getHeight());
            }

        };

        Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
        Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);     
        btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
        hfmbottom.add(btn_prev);

        Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
        Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);        
        btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
        hfmbottom.add(btn_next);


        setStatus(hfmbottom);

    }

提前致谢。

在此处输入图像描述

i want to set status bar at the bottom of screen and it should display one button left side and one right side. you can see my Screen at below.
my code is like this..

private void BottomLayout() 
    {
        Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
        final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
        HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
        {
            protected void paintBackground(Graphics graphics) 
            {
                graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );             
                super.paint(graphics);
            }
            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                super.sublayout(topBg1.getWidth(), topBg1.getHeight());
                setExtent(topBg1.getWidth(), topBg1.getHeight());
            }

        };

        Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
        Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);     
        btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
        hfmbottom.add(btn_prev);

        Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
        Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);        
        btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
        hfmbottom.add(btn_next);


        setStatus(hfmbottom);

    }

Thanks in advance.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

第七度阳光i 2025-01-08 11:29:49

我只向您发布状态栏面板。

实际上在 Horizo​​ntalFieldManager 中它确实会产生问题。

因此找到了以下方法并且有效。它确实添加了额外的代码,但它有效

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.GridFieldManager;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

class SampleBottomPanelScreen extends MainScreen {

private HorizontalFieldManager title_bar;

private VerticalFieldManager btn1_manager;
private ButtonField btn1;
private VerticalFieldManager btn2_manager;
private ButtonField btn2;
Bitmap bg_image;

public SampleBottomPanelScreen() {

    //bg_image = Bitmap.getBitmapResource("backgroundImage.png");

    btn1_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_LEFT) {

         protected void sublayout(int maxWidth, int maxHeight)
         {
                int displayWidth = Display.getWidth() / 2;
                int displayHeight = Display.getHeight();

                super.sublayout( displayWidth, displayHeight);
                setExtent( displayWidth, displayHeight);
         }  
    };

    btn2_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_RIGHT | VerticalFieldManager.USE_ALL_WIDTH) {

         protected void sublayout(int maxWidth, int maxHeight)
         {
                int displayWidth = Display.getWidth() / 2;
                int displayHeight = Display.getHeight();

                super.sublayout( displayWidth, displayHeight);
                setExtent( displayWidth, displayHeight);
         }  
    };

    title_bar = new HorizontalFieldManager(Manager.USE_ALL_WIDTH){

        public void paint(Graphics graphics) {
            graphics.setBackgroundColor(0x2bb1ff);
            graphics.clear();

            super.paint(graphics);
        }

        protected void sublayout(int maxWidth, int maxHeight)
        {
            int displayWidth = Display.getWidth();
            int displayHeight = Display.getHeight() / 8;

            super.sublayout( displayWidth, displayHeight);
            setExtent( displayWidth, displayHeight);
        }   
    };

    btn1 = new ButtonField("Submit", ButtonField.LEFT | ButtonField.FIELD_LEFT);
    btn2 = new ButtonField("Cancel", ButtonField.RIGHT| ButtonField.FIELD_RIGHT);

    btn1_manager.add(btn1);
    btn2_manager.add(btn2);

    title_bar.add(btn1_manager);
    title_bar.add(btn2_manager);

    this.add(title_bar);
}
 }

I am posting you only the status bar panel.

Actually in the HorizontalFieldManager it does create problem.

Therefore found out the following way and it is working. It does add extra code but it works

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.GridFieldManager;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

class SampleBottomPanelScreen extends MainScreen {

private HorizontalFieldManager title_bar;

private VerticalFieldManager btn1_manager;
private ButtonField btn1;
private VerticalFieldManager btn2_manager;
private ButtonField btn2;
Bitmap bg_image;

public SampleBottomPanelScreen() {

    //bg_image = Bitmap.getBitmapResource("backgroundImage.png");

    btn1_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_LEFT) {

         protected void sublayout(int maxWidth, int maxHeight)
         {
                int displayWidth = Display.getWidth() / 2;
                int displayHeight = Display.getHeight();

                super.sublayout( displayWidth, displayHeight);
                setExtent( displayWidth, displayHeight);
         }  
    };

    btn2_manager = new VerticalFieldManager(VerticalFieldManager.FIELD_RIGHT | VerticalFieldManager.USE_ALL_WIDTH) {

         protected void sublayout(int maxWidth, int maxHeight)
         {
                int displayWidth = Display.getWidth() / 2;
                int displayHeight = Display.getHeight();

                super.sublayout( displayWidth, displayHeight);
                setExtent( displayWidth, displayHeight);
         }  
    };

    title_bar = new HorizontalFieldManager(Manager.USE_ALL_WIDTH){

        public void paint(Graphics graphics) {
            graphics.setBackgroundColor(0x2bb1ff);
            graphics.clear();

            super.paint(graphics);
        }

        protected void sublayout(int maxWidth, int maxHeight)
        {
            int displayWidth = Display.getWidth();
            int displayHeight = Display.getHeight() / 8;

            super.sublayout( displayWidth, displayHeight);
            setExtent( displayWidth, displayHeight);
        }   
    };

    btn1 = new ButtonField("Submit", ButtonField.LEFT | ButtonField.FIELD_LEFT);
    btn2 = new ButtonField("Cancel", ButtonField.RIGHT| ButtonField.FIELD_RIGHT);

    btn1_manager.add(btn1);
    btn2_manager.add(btn2);

    title_bar.add(btn1_manager);
    title_bar.add(btn2_manager);

    this.add(title_bar);
}
 }
剑心龙吟 2025-01-08 11:29:49

尝试布局管理器类

    package com.doapps.blackberry.layouts;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;

public class LayoutManager extends Manager 
{
    int n;
    public LayoutManager(int n) 
    {
        super(Manager.NO_VERTICAL_SCROLL);
        this.n =n;
    }

    protected void sublayout(int width, int height)
    {
        if(n==2)
        {
            Field first = getField(0);
            Field second = getField(1);
            layoutChild(first, this.getPreferredWidth(), this.getPreferredHeight());
            layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
            setPositionChild(first,0, getPreferredHeight() -first.getHeight());
            setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -first.getHeight());

            setExtent(width, height);
        }
        if(n==1)
        {
            Field second= getField(0);
            layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
            setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -second.getHeight());
            setExtent(width, height);
        }
    }
    public int getPreferredHeight() {
        return 45;
    }

    public int getPreferredWidth() {
        return Display.getWidth();
    }
} 

try layout manager class

    package com.doapps.blackberry.layouts;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;

public class LayoutManager extends Manager 
{
    int n;
    public LayoutManager(int n) 
    {
        super(Manager.NO_VERTICAL_SCROLL);
        this.n =n;
    }

    protected void sublayout(int width, int height)
    {
        if(n==2)
        {
            Field first = getField(0);
            Field second = getField(1);
            layoutChild(first, this.getPreferredWidth(), this.getPreferredHeight());
            layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
            setPositionChild(first,0, getPreferredHeight() -first.getHeight());
            setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -first.getHeight());

            setExtent(width, height);
        }
        if(n==1)
        {
            Field second= getField(0);
            layoutChild(second, this.getPreferredWidth(), this.getPreferredHeight());
            setPositionChild(second,getPreferredWidth()-second.getWidth(), getPreferredHeight() -second.getHeight());
            setExtent(width, height);
        }
    }
    public int getPreferredHeight() {
        return 45;
    }

    public int getPreferredWidth() {
        return Display.getWidth();
    }
} 
音盲 2025-01-08 11:29:49

我认为你需要使用 GridFieldManager。根据您的需要重新排列以下代码片段并使用填充...

    private HorizontalFieldManager createRightTab () {

        HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_RIGHT);
        ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_1), button_w, button_h);
        button.setFocusListener(this);
        hMgr.add(button);

        return hMgr;
    }

    private HorizontalFieldManager createLeftTab () {

        HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_LEFT);
        ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_2), button_w, button_h);
        button.setFocusListener(this);
        hMgr.add(button);

        return hMgr;
    }

    public void GridControlScreen() {

        int w = net.rim.device.api.system.Display.getWidth();

        gridMgr = new GridFieldManager(1, 3, 0);
        gridMgr.setColumnProperty(0, GridFieldManager.FIXED_SIZE, (button_w));
        gridMgr.setColumnProperty(1, GridFieldManager.FIXED_SIZE, (w-(2*button_w)));
        gridMgr.setColumnProperty(2, GridFieldManager.FIXED_SIZE, (button_w));

        HorizontalFieldManager hMgr_a = createLeftTab();
        HorizontalFieldManager hMgr_center = new HorizontalFieldManager();
        HorizontalFieldManager hMgr_b = createRightTab();

        gridMgr.add(hMgr_a);
        gridMgr.add(hMgr_center);
        gridMgr.add(hMgr_b);

        add(gridMgr);
    }

希望这可以有所帮助。

I think you need to use GridFieldManager. Rearrange the following code fragment to your needs and play with paddings ...

    private HorizontalFieldManager createRightTab () {

        HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_RIGHT);
        ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_1), button_w, button_h);
        button.setFocusListener(this);
        hMgr.add(button);

        return hMgr;
    }

    private HorizontalFieldManager createLeftTab () {

        HorizontalFieldManager hMgr = new HorizontalFieldManager(Field.FIELD_LEFT);
        ImageButtonField button = new ImageButtonField ( Bitmap.getBitmapResource(res.button_2), button_w, button_h);
        button.setFocusListener(this);
        hMgr.add(button);

        return hMgr;
    }

    public void GridControlScreen() {

        int w = net.rim.device.api.system.Display.getWidth();

        gridMgr = new GridFieldManager(1, 3, 0);
        gridMgr.setColumnProperty(0, GridFieldManager.FIXED_SIZE, (button_w));
        gridMgr.setColumnProperty(1, GridFieldManager.FIXED_SIZE, (w-(2*button_w)));
        gridMgr.setColumnProperty(2, GridFieldManager.FIXED_SIZE, (button_w));

        HorizontalFieldManager hMgr_a = createLeftTab();
        HorizontalFieldManager hMgr_center = new HorizontalFieldManager();
        HorizontalFieldManager hMgr_b = createRightTab();

        gridMgr.add(hMgr_a);
        gridMgr.add(hMgr_center);
        gridMgr.add(hMgr_b);

        add(gridMgr);
    }

Hope this can help.

随遇而安 2025-01-08 11:29:49

试试这个

private void BottomLayout() 
    {
        Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
        final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
        HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
        {
            protected void paintBackground(Graphics graphics) 
            {
                graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );             
                super.paint(graphics);
            }
            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                super.sublayout(topBg1.getWidth(), topBg1.getHeight());
                setExtent(topBg1.getWidth(), topBg1.getHeight());
            }

        };

        Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
        Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);     
        btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
        hfmbottom.add(btn_prev);

        Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
        Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);        
        btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
        btn_next.setPadding(0, 0, 0, Display.getWidth()-btn_prev.getWidth()-btn_next.getWidth());
        hfmbottom.add(btn_next);


        setStatus(hfmbottom);

    }

Try this

private void BottomLayout() 
    {
        Bitmap topBg = Bitmap.getBitmapResource(ImageName.topbar);
        final Bitmap topBg1 = cmn_fun.resizeBitmap(topBg, SCREEN_WIDTH, topBg.getHeight());
        HorizontalFieldManager hfmbottom = new HorizontalFieldManager(Field.USE_ALL_WIDTH)
        {
            protected void paintBackground(Graphics graphics) 
            {
                graphics.drawBitmap(0,0,SCREEN_WIDTH,topBg1.getHeight(), topBg1,0,0 );             
                super.paint(graphics);
            }
            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                super.sublayout(topBg1.getWidth(), topBg1.getHeight());
                setExtent(topBg1.getWidth(), topBg1.getHeight());
            }

        };

        Bitmap imgprv=Bitmap.getBitmapResource(ImageName.btn_prev);
        Bitmap imgprv_sel=Bitmap.getBitmapResource(ImageName.btn_prev_sel);     
        btn_prev=new CustomButtonField(0, "", imgprv_sel, imgprv, Field.FIELD_LEFT);
        hfmbottom.add(btn_prev);

        Bitmap imgnext=Bitmap.getBitmapResource(ImageName.btn_next);
        Bitmap imgnext_sel=Bitmap.getBitmapResource(ImageName.btn_next_sel);        
        btn_next=new CustomButtonField(0, "", imgnext_sel, imgnext, Field.FIELD_RIGHT);
        btn_next.setPadding(0, 0, 0, Display.getWidth()-btn_prev.getWidth()-btn_next.getWidth());
        hfmbottom.add(btn_next);


        setStatus(hfmbottom);

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文