2010-11-08 81 views

回答

1

您想自定義彈出屏幕這樣

public class CustomPopUpScreen extends PopupScreen { 
    public CustomPopUpScreen() { 
     super(new VerticalFieldManager(CustomPopUpScreen.NO_HORIZONTAL_SCROLL)); 
     add(new ButtonField()); 
     add(new ButtonField()); 
    } 
} 

此代碼將幫助您

1

在這裏,我創建PopupScreen類型的對象,並調用該方法givePopup

PopupScreen popup1=givePopup(); 
PopupScreen givePopup(){ 
    VerticalFieldManager popvfm =new VerticalFieldManager(); 
    ButtonField ok=new ButtonField("ok"); 
    ButtonField cancel=new ButtonField("cancel"); 
    popvfm.add(ok); 
    popvfm.add(cancel); 
    PopupScreen popup=new PopupScreen(popvfm); 
    return popup; 
} 

這種方法返回一個具有一個垂直字段管理器的實例,並在此管理器上添加兩個按鈕字段。

1
public class FriendPopupScreen extends MainScreen{ 
    int dialogWidth; 
    int dialogHeight; 
    LabelField lblTitle; 

    HorizontalFieldManager hfmTitle; 

    Vector data; 

    public FriendPopupScreen() { 

     dialogWidth = 300; 
     dialogHeight = 150; 

     lblTitle = newLabelField("Choose option"); 

     hfmTitle = new HorizontalFieldManager(USE_ALL_WIDTH){ 

      protected void sublayout(int maxWidth, int maxHeight) { 
       // TODO Auto-generated method stub 
       maxWidth= Display.getWidth(); 
       maxHeight=40; 
       super.sublayout(maxWidth, maxHeight); 
       setExtent(maxWidth, maxHeight); 
      } 

      protected void paint(Graphics graphics) { 
       // TODO Auto-generated method stub 

       graphics.setBackgroundColor(Color.BLACK); 
       graphics.clear(); 
       super.paint(graphics); 
      } 

     }; 

     hfmTitle.add(lblTitle); 
     lblTitle.setMargin(10,0,0,10); 
     add(hfmTitle); 
    } 
    protected void sublayout(int width, int height) { 
      setExtent(dialogWidth, dialogHeight); 
      setPosition(Display.getWidth()/2-(dialogWidth/2), Display.getHeight()/2 - (dialogHeight/2)); 
      layoutDelegate(dialogWidth, dialogHeight); 
     } 
} 

並稱之爲:

FriendPopupScreen popup = new FriendPopupScreen(); 
UiApplication.getUiApplication().pushModalScreen(popup);