2009-09-01 7 views
0

J'ai un tableau de gestionnaire horizontal qui se composent de editfield, dropdown, étiquette et un bouton. Je place tout ce tableau de gestionnaire horizontalfield dans un gestionnaire vertical pour faire une table comme la structure de grille. Je peux le faire mais je veux le faire si nous mettons l'accent sur le gestionnaire horizontal alors tous les composants dans le gestionnaire horizontal devraient donner une même couleur je ne sais pas comment faire cela.Blackberry changer la couleur des champs enfant sur le focus du gestionnaire horizontal

Répondre

3

Si vous en 4,5 et inférieur, prolongez HorizontalFieldManager, ajoutez la propriété de couleur, de l'utiliser sur l'événement de peinture et d'annuler le point changement:

class Scr extends MainScreen { 
HorizontalFieldManager mMainPanel; 
VerticalFieldManager mVerticalPanel; 

public Scr() { 
    mMainPanel = new HorizontalFieldManager(); 
    add(mMainPanel); 

    mVerticalPanel = new VerticalFieldManager(USE_ALL_HEIGHT 
    | USE_ALL_WIDTH); 
    mMainPanel.add(mVerticalPanel); 
    for (int i = 0; i < 5; i++) { 
    HFMHighlight hfm = new HFMHighlight(); 
    hfm.setHightlightColor(Color.GRAY); 
    hfm.add(new LabelField("Label " + i, FIELD_LEFT)); 
    hfm.add(new BasicEditField(FIELD_RIGHT)); 
    mVerticalPanel.add(hfm); 
    } 
} 
} 

class HFMHighlight extends HorizontalFieldManager { 

int mHColor = -1; 

public void setHightlightColor(int color) { 
    mHColor = color; 
} 

protected void onFocus(int direction) { 
    invalidate(); 
    super.onFocus(direction); 
} 

protected void onUnfocus() { 
    invalidate(); 
    super.onUnfocus(); 
} 

public void paint(Graphics graphics) { 
    if (-1 != mHColor && isFocus()) { 
    graphics.setBackgroundColor(mHColor); 
    graphics.clear(); 
    } 
    super.paint(graphics); 
} 
} 

Si vous en 4.6 et plus, l'utilisation setBackground pour FOCUS ÉTAT VISUEL:

class Scr extends MainScreen { 
    HorizontalFieldManager mMainPanel; 
    VerticalFieldManager mVerticalPanel; 

    public Scr() { 
     RadioInfo.isDataServiceOperational(); 
     CoverageInfo.isOutOfCoverage(); 
     WLANInfo.getWLANState(); 

     mMainPanel = new HorizontalFieldManager(); 
     add(mMainPanel); 
     mVerticalPanel = new VerticalFieldManager(USE_ALL_HEIGHT 
       | USE_ALL_WIDTH); 
     mMainPanel.add(mVerticalPanel); 
     for (int i = 0; i < 5; i++) { 
      HFMHighlight hfm = new HFMHighlight(Color.GRAY); 
      hfm.add(new LabelField("Label " + i, FIELD_LEFT)); 
      hfm.add(new BasicEditField(FIELD_RIGHT)); 
      mVerticalPanel.add(hfm); 
     } 
    } 
} 

class HFMHighlight extends HorizontalFieldManager { 

    public HFMHighlight(int color) { 
     Background focusedBG = BackgroundFactory.createSolidBackground(color); 
     setBackground(VISUAL_STATE_FOCUS, focusedBG); 
    } 

    protected void onFocus(int direction) { 
     invalidate(); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     invalidate(); 
     super.onUnfocus(); 
    } 
} 

et voici un cas si vous voulez mettre en évidence toutes les commandes (bouton, case à cocher, choix et modifier) ​​si gestionnaire horizontal est focalisé:

class Scr extends MainScreen { 
    HorizontalFieldManager mMainPanel; 
    VerticalFieldManager mVerticalPanel; 

    public Scr() { 
     mMainPanel = new HorizontalFieldManager(); 
     add(mMainPanel); 
     mVerticalPanel = new VerticalFieldManager(USE_ALL_HEIGHT 
       | USE_ALL_WIDTH); 
     mMainPanel.add(mVerticalPanel); 
     for (int i = 0; i < 5; i++) { 
      HHorizontalFieldManager hfm = new HHorizontalFieldManager(); 
      mVerticalPanel.add(hfm); 
      HButtonField button = new HButtonField("btn"); 
      button.setHightlightColor(Color.GRAY); 
      hfm.add(button); 
      HCheckboxField checkbox = new HCheckboxField("chk box", false); 
      checkbox.setHightlightColor(Color.GRAY); 
      hfm.add(checkbox); 
      String choiceItems[] = { "one", "two", "three" }; 
      HObjectChoiceField dropdown = new HObjectChoiceField("choice", 
        choiceItems); 
      dropdown.setHightlightColor(Color.GRAY); 
      hfm.add(dropdown);   
      HEditField edit = new HEditField("edit", "___"); 
      edit.setHightlightColor(Color.GRAY); 
      hfm.add(edit); 
     } 
    } 
} 

class HHorizontalFieldManager extends HorizontalFieldManager { 
    public HHorizontalFieldManager() { 
     super(); 
    } 

    public HHorizontalFieldManager(long style) { 
     super(style); 
    } 

    protected void onFocus(int direction) { 
     invalidate(); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     invalidate(); 
     super.onUnfocus(); 
    } 

    public void paint(Graphics graphics) { 
     if (isFocus()) { 
      graphics.setBackgroundColor(Color.GRAY); 
      graphics.clear(); 
     } 
     super.paint(graphics); 
    } 
} 

class HEditField extends EditField { 

    public HEditField() { 
     super(); 
    } 

    public HEditField(long style) { 
     super(style); 
    } 

    public HEditField(String label, String initialValue, int maxNumChars, 
      long style) { 
     super(label, initialValue, maxNumChars, style); 
    } 

    public HEditField(String label, String initialValue) { 
     super(label, initialValue); 
    } 

    private int mHColor = -1; 

    public void setHightlightColor(int color) { 
     mHColor = color; 
    } 

    protected void onFocus(int direction) { 
     invalidate(); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     invalidate(); 
     super.onUnfocus(); 
    } 

    public void paint(Graphics graphics) { 
     if (-1 != mHColor && getManager().isFocus()) { 
      graphics.setBackgroundColor(mHColor); 
      graphics.clear(); 
     } 
     super.paint(graphics); 
    } 
} 

class HButtonField extends ButtonField { 

    public HButtonField() { 
     super(); 
    } 

    public HButtonField(long style) { 
     super(style); 
    } 

    public HButtonField(String label, long style) { 
     super(label, style); 
    } 

    public HButtonField(String label) { 
     super(label); 
    } 

    private int mHColor = -1; 

    public void setHightlightColor(int color) { 
     mHColor = color; 
    } 

    protected void onFocus(int direction) { 
     invalidate(); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     invalidate(); 
     super.onUnfocus(); 
    } 

    public void paint(Graphics graphics) { 
     if (-1 != mHColor && getManager().isFocus()) { 
      graphics.setBackgroundColor(mHColor); 
      graphics.clear(); 
     } 
     super.paint(graphics); 
    } 
} 

class HCheckboxField extends CheckboxField { 

    public HCheckboxField() { 
     super(); 
    } 

    public HCheckboxField(String label, boolean checked, long style) { 
     super(label, checked, style); 
    } 

    public HCheckboxField(String label, boolean checked) { 
     super(label, checked); 
    } 

    private int mHColor = -1; 

    public void setHightlightColor(int color) { 
     mHColor = color; 
    } 

    protected void onFocus(int direction) { 
     invalidate(); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     invalidate(); 
     super.onUnfocus(); 
    } 

    public void paint(Graphics graphics) { 
     if (-1 != mHColor && getManager().isFocus()) { 
      graphics.setBackgroundColor(mHColor); 
      graphics.clear(); 
     } 
     super.paint(graphics); 
    } 
} 

class HObjectChoiceField extends ObjectChoiceField { 
    public HObjectChoiceField() { 
     super(); 
    } 

    public HObjectChoiceField(String label, Object[] choices, 
     int initialIndex, long style) { 
     super(label, choices, initialIndex, style); 
    } 

    public HObjectChoiceField(String label, Object[] choices, 
      int initialIndex) { 
     super(label, choices, initialIndex); 
    } 

    public HObjectChoiceField(String label, Object[] choices, 
      Object initialObject) { 
     super(label, choices, initialObject); 
    } 

    public HObjectChoiceField(String label, Object[] choices) { 
     super(label, choices); 
    } 

    private int mHColor = -1; 

    public void setHightlightColor(int color) { 
     mHColor = color; 
    } 

    protected void onFocus(int direction) { 
     invalidate(); 
     super.onFocus(direction); 
    } 

    protected void onUnfocus() { 
     invalidate(); 
     super.onUnfocus(); 
    } 

    public void paint(Graphics graphics) { 
     if (-1 != mHColor && getManager().isFocus()) { 
      graphics.setBackgroundColor(mHColor); 
      graphics.clear(); 
     } 
     super.paint(graphics); 
    } 
} 
+0

Salut merci pour votre aide mais quand j'utilise mon code je peux seulement changer la couleur du gestionnaire horizontal aucune couleur des composants est changée je veux changer tous les composants couleur aussi à changer lorsque le gain de focus au gestionnaire horizontal. – Kumar

+0

De rien! Je pense, c'est assez bon pour colorer le gestionnaire seulement. Mais si vous voulez colorer chaque champ à l'intérieur, vous devrez me dire quels champs utilisez-vous exactement? La chose est que nous devrons faire ce que j'ai fait à tous les domaines à l'intérieur du gestionnaire. Nous devrons donc mettre en place notre propre classe pour chaque type de domaine. –

+0

Lorsque j'utilise editfield, buttonfield, dropdownfield et checkboxfield, ce sont les champs que j'ai utilisés dans le gestionnaire. – Kumar

Questions connexes