2012-01-20 108 views
3

enter image description here標籤欄沒有ToolBarManager

我想創建一個確切的外觀的工具欄和感覺我的BlackBerry項目。任何幫助是極大的讚賞。請注意我不能使用ToolBarManager。我的項目應該OS之後的設備都支持5.0

感謝

+0

我可以根據您的要求提供所有示例代碼。看到這個鏈接:http://www.flickr.com/photos/[email protected]/6734580553/in/photostream – alishaik786

回答

8

這是一個示例代碼,如何在黑莓創建標籤。 我有總共3個屏幕後statUp(其延伸的UIApplication)類

  1. LoadingScreen.java

    public class LoadingScreen extends MainScreen 
    { 
    int current_index=0; 
    BottomPanel bottomPanel; 
    public LoadingScreen(int current_index) 
    { 
        this.current_index=current_index; 
        bottomPanel=new BottomPanel(current_index); 
    } 
    
    public void createGUI() 
    {  
    setTitle("Loading Screen"); 
    
    VerticalFieldManager vertical=new VerticalFieldManager(USE_ALL_WIDTH) 
    { 
        protected void sublayout(int maxWidth, int maxHeight) 
        {    
         super.sublayout(Display.getWidth(), 150); 
         setExtent(Display.getWidth(), 150); 
        } 
    }; 
    vertical.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN)); 
    ButtonField button=new ButtonField("Click"); 
    vertical.add(button);  
    add(vertical); 
    
    setStatus(bottomPanel);  
    } 
    } 
    
  2. BottomPanel.java

    public class BottomPanel extends VerticalFieldManager implements FieldChangeListener 
    { 
        Bitmap news_bit=Bitmap.getBitmapResource("news.png");//these images are cutting according to device requirement; 
        Bitmap news_bit_hover=Bitmap.getBitmapResource("news_h.png"); 
        Bitmap settings_bit=Bitmap.getBitmapResource("settings.png"); 
        Bitmap settings_bit_hover=Bitmap.getBitmapResource("settings_h.png"); 
        Bitmap about_bit=Bitmap.getBitmapResource("about.png"); 
        Bitmap about_bit_hover=Bitmap.getBitmapResource("about_h.png"); 
        PictureBackgroundButtonField news_pic,settings_pic,about_pic; 
        HorizontalFieldManager hr; 
        int current_index=0; 
        public BottomPanel(int current_index) 
        {   
        super(FOCUSABLE); 
        this.current_index=current_index; 
        VerticalFieldManager ver=new VerticalFieldManager(USE_ALL_WIDTH|USE_ALL_HEIGHT) 
        {   
        protected void sublayout(int width, int height) 
        { 
         super.sublayout(width, news_bit.getHeight()); 
         setExtent(width, news_bit.getHeight()); 
        } 
    }; 
    hr=new HorizontalFieldManager(FIELD_HCENTER); 
    if(current_index==1) 
    { 
        news_pic=new PictureBackgroundButtonField(news_bit.getWidth(),news_bit.getHeight(), Field.NON_FOCUSABLE|Field.FIELD_VCENTER, news_bit_hover, news_bit_hover); 
    } 
    else 
    { 
        news_pic=new PictureBackgroundButtonField(news_bit.getWidth(),news_bit.getHeight(), Field.FOCUSABLE|Field.FIELD_VCENTER, news_bit, news_bit_hover); 
    } 
    news_pic.setChangeListener(this); 
    hr.add(news_pic); 
    
    if(current_index==2) 
    { 
        settings_pic=new PictureBackgroundButtonField(settings_bit.getWidth(),settings_bit.getHeight(), Field.NON_FOCUSABLE|Field.FIELD_VCENTER, settings_bit_hover, settings_bit_hover); 
    } 
    else 
    { 
        settings_pic=new PictureBackgroundButtonField(settings_bit.getWidth(),settings_bit.getHeight(), Field.FOCUSABLE|Field.FIELD_VCENTER, settings_bit, settings_bit_hover); 
    } 
    settings_pic.setChangeListener(this); 
    hr.add(settings_pic); 
    
    if(current_index==3) 
    { 
        about_pic=new PictureBackgroundButtonField(about_bit.getWidth(),about_bit.getHeight(),Field.NON_FOCUSABLE|Field.FIELD_VCENTER, about_bit_hover, about_bit_hover); 
    } 
    else 
    { 
        about_pic=new PictureBackgroundButtonField(about_bit.getWidth(),about_bit.getHeight(), Field.FOCUSABLE|Field.FIELD_VCENTER, about_bit, about_bit_hover); 
    } 
    about_pic.setChangeListener(this); 
    hr.add(about_pic); 
    
    ver.add(hr); 
    add(ver); 
    } 
    
    public void fieldChanged(Field field, int context) 
    {   
    if(field==news_pic) 
    {    
        LoadingScreen loadingScreen=new LoadingScreen(1); 
        UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); 
        UiApplication.getUiApplication().pushScreen(loadingScreen); 
        loadingScreen.createGUI(); 
    } 
    else if(field==settings_pic) 
    { 
        LoadingScreen loadingScreen=new LoadingScreen(2); 
        UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); 
        UiApplication.getUiApplication().pushScreen(loadingScreen); 
        loadingScreen.createGUI(); 
    } 
    else if(field==about_pic) 
    { 
        LoadingScreen loadingScreen=new LoadingScreen(3); 
        UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen()); 
        UiApplication.getUiApplication().pushScreen(loadingScreen); 
        loadingScreen.createGUI(); 
    }  
    } 
    } 
    
  3. PictureBackgroundButtonField.java

    public class PictureBackgroundButtonField extends Field 
    {  
        private String _label; 
        private int _labelHeight; 
        private int _labelWidth; 
        private Font _font; 
    
        private Bitmap _currentPicture; 
        private Bitmap _onPicture ; 
        private Bitmap _offPicture ; 
        public PictureBackgroundButtonField(int width,int height, long style, Bitmap picture, Bitmap selectedPic) 
        { 
         super(style); 
    
         _font = getFont(); 
         _label = ""; 
         _labelHeight = height; 
         _labelWidth = width; 
         _currentPicture = picture; 
         _onPicture = selectedPic; 
         _offPicture = picture;   
        } 
        public int getPreferredHeight() 
        { 
         return _labelHeight; 
        } 
        public int getPreferredWidth() 
        { 
         return _labelWidth; 
        } 
        protected void onFocus(int direction) 
        { 
         _currentPicture = _onPicture; 
         invalidate(); 
        } 
        protected void onUnfocus() 
        { 
         _currentPicture = _offPicture; 
         invalidate(); 
        } 
        protected void drawFocus(Graphics graphics, boolean on) 
        { 
         // Do nothing 
        } 
        protected void layout(int width, int height) 
        { 
         setExtent(getPreferredWidth(), getPreferredHeight()); 
        } 
        protected void paint(Graphics graphics) 
        {    
          graphics.drawBitmap(0, 0, getPreferredWidth(), getPreferredHeight(), _currentPicture, 0, 0);  
          graphics.setFont(_font); 
          graphics.drawText(_label, 4, 2, 
        (int)(getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK), 
        getWidth() - 6); 
        } 
        protected boolean navigationClick(int status, int time) 
        { 
         fieldChangeNotify(1); 
         return true; 
        }  
    } 
    

試試這個代碼,看到了差距;

+0

我也在做同樣的方式哥們.. –

+0

嘿alishaik786-我試過這段代碼它運行,但我不能請參閱標籤欄。我在這個應用程序中使用我的圖像。怎麼回事?原因是什麼? –

+0

你使用這種方法setStatus(bottomPanel);在你的代碼中; – alishaik786

2

setStatus(bottomPanel);放在LoadingScreen的構造函數中。