在黑莓objectchoicefield和ButtonField字段删除上调影响 [英] Remove raised effect in blackberry objectchoicefield and buttonfield

查看:138
本文介绍了在黑莓objectchoicefield和ButtonField字段删除上调影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现黑莓的控制,即objectchoicefield和平面外观ButtonField字段。

I am trying to achieve a flat look for blackberry controls, namely objectchoicefield and buttonfield.

以下code似乎没有这样的伎俩。 (宽度设定的工作,但并不边境设置。)

The following code does not seem to do the trick. (The width setting does work, but not the border setting.)

public static ObjectChoiceField GetDropdownList(String label, String[] data)
{
    ObjectChoiceField ocf = new ObjectChoiceField(null, data, 0, Field.FIELD_LEFT);

    ocf.setBorder(BorderFactory.createSimpleBorder(new XYEdges(0,0,0,0)));
    ocf.setMinimalWidth(Display.getWidth()-61);

    return ocf;
}

我得到了相同的外观使用或不使用setBorder声明。基本上我不希望任何三维外观或阴影或亮或圆角。

I get the same appearance with or without the setBorder statement. Basically I do not want any 3D look or shadow or shine or rounded corners.

感谢

推荐答案

这可能不是做的所有你想要的,但你可以尝试寻找的在这个定制ObjectChoiceField 的,我专为OS 4.6的的设备。我想的添加的光泽,3D外观,但您可以更改自定义的paint() code我用来做一个简单的,奉承的样子。

This might not do everything you want, but you can try looking at this custom ObjectChoiceField that I built for OS 4.6 and lower devices. I wanted to add a glossy, 3D look, but you could change the custom paint() code I used to make a simpler, flatter look.

以我的例子中,改变了圆角半径为1,除去调用 super.paint(G)给出这样的:

Taking my example, changing the rounded corner radius to 1, and removing the call to super.paint(g) gives something like this:

public class CustomChoiceField extends ObjectChoiceField {

   private int _bgWidth = 0;
   private int _bgHeight = 0;
   private int _numChoices = 0;
   private boolean _hasFocus = false;
   private static final int HIGHLIGHT_COLOR = 0xFF185AB5;  // blue-ish
   private static final int RADIUS = 1;    // rounded corner radius in pixels
   private static final int DFLT_PADDING = 20;

   public CustomChoiceField(Object[] choices, int initialIndex) {
      super("", choices, initialIndex);
      _numChoices = choices.length;
   }

   public int getPreferredHeight() {
      return _bgHeight;
   }

   public int getPreferredWidth() {
      return _bgWidth;
   }

   protected void layout(int width, int height) {
      if (_bgWidth == 0 || _bgHeight == 0) {
         if (height <= Display.getHeight()) {
            // probably using custom Manager to specify size
            _bgWidth = width;
            _bgHeight = height;
         } else {
            // use default sizing
            _bgHeight = DFLT_PADDING + getHeightOfChoices();
            for (int i = 0; i < _numChoices; i++) {
               _bgWidth = Math.max(_bgWidth, DFLT_PADDING + getWidthOfChoice(i));
            }
         }
      }

      super.layout(_bgWidth, _bgHeight);
      super.setExtent(_bgWidth, _bgHeight);
   }   

   protected void applyTheme(Graphics arg0, boolean arg1) {
      // do nothing
   }

   protected void drawFocus(Graphics g, boolean on) {
      // do nothing .. handled manually in paint(g)
   }

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

   protected void onUnfocus() {
      _hasFocus = false;
      super.onUnfocus();
      invalidate();  // required to clear focus
   }

   protected void paint(Graphics g) {
      int oldColor = g.getColor();

      // field color depends on whether we have focus or not
      int bgColor = (_hasFocus) ? HIGHLIGHT_COLOR : Color.BLACK;
      // when the field has focus, we make it a little less transparent
      int alpha = (_hasFocus) ? 0xDD : 0xBB;
      g.setColor(bgColor);
      g.setGlobalAlpha(alpha);
      g.fillRoundRect(0, 0, _bgWidth, _bgHeight, RADIUS, RADIUS);

      // draw a plain white line as a border
      g.setColor(Color.WHITE);
      g.setGlobalAlpha(0xFF);
      g.drawRoundRect(0, 0, _bgWidth, _bgHeight, RADIUS, RADIUS);

      // draw the currently selected choice's text (also in white)
      String text = (String)getChoice(getSelectedIndex());
      int y = (_bgHeight - getFont().getHeight()) / 2;
      g.drawText(text, 0, y, DrawStyle.HCENTER | DrawStyle.TOP, _bgWidth);
      g.setColor(oldColor);
   }
}

和使用 CustomChoiceField 是这样的:

   private ObjectChoiceField[] ocf = new ObjectChoiceField[3];

   public ObjectChoiceScreen() {
      super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
      Object[] choices1 = new Object[] { "one", "two", "three" };
      ocf[0] = new CustomChoiceField(choices1, 0);
      Object[] choices2 = new Object[] { "ichi", "ni", "san" };
      ocf[1] = new CustomChoiceField(choices2, 0);
      Object[] choices3 = new Object[] { "uno", "dos", "tres" };
      ocf[2] = new CustomChoiceField(choices3, 0);
      for (int i = 0; i < ocf.length; i++) {
         ocf[i].setMargin(new XYEdges(10, 10, 10, 10));
      }
      getMainManager().addAll(ocf);

这是不是生产code,所以你需要自己进行测试。例如,它不能处理 setChoices变更选择()。但是,这是一个开始,会得到你是这样的:

This isn't production code, so you'll need to test it yourself. For example, it doesn't handle changing the choices with setChoices(). But, it's a start, and will get you something like this:

您会发现前两个对象的选择字段,底面合一,集中之间的颜色差异。

You'll notice the difference in color between the first two object choice fields, and the bottom one, which is focused.

我的code有选择的选择为正常 ObjectChoiceField 一样弹出。所以,你仍然可以得到圆角的方式。就我而言,我并不需要更改的外观和感觉,所以我不知道你将如何改变这一点。

My code has the same popup for selecting choices as the normal ObjectChoiceField. So, you still may get rounded corners that way. In my case, I didn't need to change that look and feel, so I'm not sure how you might change that, too.

这篇关于在黑莓objectchoicefield和ButtonField字段删除上调影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆