Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8116721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:55:11+00:00 2026-06-06T03:55:11+00:00

In BlackBerry, how to change the ButtonField background color during the click event? For

  • 0

In BlackBerry, how to change the ButtonField background color during the click event? For example, for the long press the background color needs to change. For me it takes the default color blue. How to change it?

This is our custom buttton field. But it shows the default blue color for the button click event.

public class CustomButtonField extends ButtonField implements GlobalConstant {
int mHeight;
int mWidth;
public final static int DEFAULT_BACKGROUND_COLOR_NORMAL = 0x167c9c;
public final static int DEFAULT_BACKGROUND_COLOR_ON_FOCUS = 0x188118;
private int backgroundColorNormal = DEFAULT_BACKGROUND_COLOR_NORMAL;
private int backgroundColorOnFocus = DEFAULT_BACKGROUND_COLOR_ON_FOCUS;
private Background noraml_bg;
private Background focus_bg;
private boolean isFocusable;
private boolean isround_button = false;


public CustomButtonField(int height, int width, String label) {
    super(label, CONSUME_CLICK);

    noraml_bg = menuButton_bgNormal;
    focus_bg = menuButton_bgFocus;

    mHeight = height;
    mWidth = width;
    this.isFocusable = true;
    setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE,
            BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));

}

public CustomButtonField(int height, int width, String label, boolean isround_button) {
    super(label, CONSUME_CLICK);

    this.isround_button = isround_button;
    noraml_bg = roundButton_bgNormal;
    focus_bg = roundButton_bgFocus;
    mHeight = height;
    mWidth = width;
    this.isFocusable = true;

    XYEdges padding = new XYEdges(1,1,1,1);
    XYEdges color = new XYEdges (Color.BLACK,Color.BLACK,Color.BLACK,Color.BLACK);
    int lineStyle = Border.STYLE_SOLID;

   Border roundedBorder = BorderFactory.createSimpleBorder(padding, color, lineStyle);
    setBorder(roundedBorder);

}

/*
 * (non-Javadoc)
 * 
 * @see net.rim.device.api.ui.component.ButtonField#getPreferredHeight()
 */
public int getPreferredHeight() {
    return mHeight;
}

/*
 * (non-Javadoc)
 * 
 * @see net.rim.device.api.ui.component.ButtonField#getPreferredWidth()
 */
public int getPreferredWidth() {
    return mWidth;
}

/*
 * (non-Javadoc)
 * 
 * @see net.rim.device.api.ui.component.ButtonField#layout(int, int)
 */
protected void layout(int width, int height) {
    super.layout(mWidth, mHeight);
    setExtent(mWidth, mHeight);
}

/*
 * (non-Javadoc)
 * 
 * @see
 * net.rim.device.api.ui.component.ButtonField#paint(net.rim.device.api.
 * ui.Graphics)
 */
protected void paint(Graphics graphics) {

    String label = getLabel();
    int x = (getPreferredWidth() - getFont().getAdvance(label)) >> 1;
    int y = (getPreferredHeight() - getFont().getHeight()) >> 1;
    if (isFocus() == false) {
        this.setBackground(noraml_bg);
        if(isround_button){
            graphics.setColor(0x666666);
        }else{
            graphics.setColor(Color.WHITE);
        }

        graphics.drawText(label, x, y);
    } else {
        this.setBackground(focus_bg);
        graphics.setColor(Color.WHITE);

        graphics.drawText(label, x, y);
    }
}

protected void drawFocus(Graphics graphics, boolean on) {
    if (on) {
        graphics.setColor(backgroundColorOnFocus);
    } else {
        graphics.setColor(backgroundColorNormal);
    }
}

public boolean isFocusable() {
    return isFocusable;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:55:14+00:00Added an answer on June 6, 2026 at 3:55 am

    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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to listen file change event in BlackBerry base on FileExplorer example, but
I have defined a BitmapButtonField in Blackberry. But the default grey color background does
i need to build an app for blackberry that will change the background color
The default highlight color in blackberry is blue. I'm currently doing an application which
I want to change the background screens of one of my Blackberry app and
I'm developing my first BlackBerry application and I want to change the background to
I want to change background color of selected item in object choice Field in
How can we change a font color while using Rich List in Blackberry.
How to change color of specific text only in textbox for Blackberry applications?
I have a Blackberry project in which I want to change normal image to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.