To change the ButtonField background during click event in BlackBerry

老子叫甜甜 提交于 2019-12-04 17:41:00

Using visual states indicator of the Field, and BackgroundFactory you can set Background for following visual states:

  • VISUAL_STATE_ACTIVE - Active visual state. The user is interacting with the field.
  • VISUAL_STATE_DISABLED - Disabled visual state. There is no possible interaction with the field.
  • VISUAL_STATE_DISABLED_FOCUS - Disabled, but focused visual state. The field is highlighted, but there is no other possible interaction with the field.
  • VISUAL_STATE_FOCUS - Focus visual state. The field has focus (is highlighted).
  • VISUAL_STATE_NORMAL - Normal visual state. There is no current interaction with the field.


Check following code snippet:

ButtonField bfTest = new ButtonField("Button Field");

Background commonBgOne = BackgroundFactory.createSolidBackground(Color.RED);
Background commonBgTwo = BackgroundFactory.createSolidBackground(Color.GREEN);

bfTest.setBackground(VISUAL_STATE_ACTIVE, commonBgOne);
bfTest.setBackground(VISUAL_STATE_DISABLED, commonBgTwo);
bfTest.setBackground(VISUAL_STATE_DISABLED_FOCUS, commonBgTwo);
bfTest.setBackground(VISUAL_STATE_FOCUS, commonBgOne);
bfTest.setBackground(VISUAL_STATE_NORMAL, commonBgTwo);


Cancelling default border

Border commonBorder = BorderFactory.createSimpleBorder(new XYEdges());

bfTest.setBorder(VISUAL_STATE_ACTIVE, commonBorder);
bfTest.setBorder(VISUAL_STATE_DISABLED, commonBorder);
bfTest.setBorder(VISUAL_STATE_DISABLED_FOCUS, commonBorder);
bfTest.setBorder(VISUAL_STATE_FOCUS, commonBorder);
bfTest.setBorder(VISUAL_STATE_NORMAL, commonBorder);

Have you tried using setBackground property of a button?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!