2012-06-04 13 views
0

這是一場具有相同的Android linear layout如何在黑莓中創建小部件?

public class Custom_TopField extends VerticalFieldManager { 
    private static final int FIELD_HEIGHT = 70; 

    private String _text; 

    Custom_TopField(int color, String text) { 
     super(Manager.NO_VERTICAL_SCROLL); 
     _text = text; 

     Background background = BackgroundFactory.createSolidBackground(color); 
     setBackground(background); 
    } 

    protected void sublayout(int width, int height) { 
     width = Math.min(width, getPreferredWidth()); 
     height = Math.min(height, getPreferredHeight()); 
     setExtent(width, height); 
    } 

    public int getPreferredHeight() { 
     return FIELD_HEIGHT; 
    } 

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

    public void paint(Graphics graphics) { 
     int rectHeight = getPreferredHeight(); 
     int rectWidth = getPreferredWidth(); 

     Font font = Font.getDefault().derive(Font.BOLD, 65); 
     graphics.drawRect(0, 0, rectWidth, rectHeight); 
     graphics.drawText(_text, rectWidth/2, 10); 
     graphics.setFont(font); 
     graphics.setColor(Color.WHITE); 
     super.paint(graphics); 
    } 
} 

輸出=紅色背景和字體我的自定義佈局=黑色

我要的是紅色背景,白色字體,字體大小40

我也想知道如何以編程方式創建小部件?

回答

0

的字體爲白色,大小爲40改變油漆如下:

public void paint(Graphics graphics) { 
    int rectHeight = getPreferredHeight(); 
    int rectWidth = getPreferredWidth(); 

    Font font = Font.getDefault().derive(Font.BOLD, 40); 
    graphics.setColor(Color.WHITE); 
    graphics.setFont(font); 
    graphics.drawRect(0, 0, rectWidth, rectHeight); 
    graphics.drawText(_text, rectWidth/2, 10); 
    super.paint(graphics); 
} 
+0

得到它。那麼在黑莓中創建一個textview(android)呢? –

+0

你用textview是什麼意思? –

+0

android中的textview小部件是靜態文本,我想在黑莓中調用 –