Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

ButtonField Focus Color

Hi

I have a ButtonField on screen. I want to set Background color of the button orange and Text color black. When Buttonfield is in focus color of text should be changed to white. How to do this?

I have used following code. In this code m unable to set background color to whole button. It is set only to area behind text.

 

ButtonField btn = new ButtonField("Test",ButtonField.USE_ALL_WIDTH|ButtonField.FIELD_HCENTER)
{
boolean focused = false;
protected void paint(Graphics graphics)
{
graphics.setBackgroundColor( 0x00D8632E );

if(focused)
graphics.setColor(Color.WHITE);
else
graphics.setColor(Color.BLACK);

graphics.clear();
super.paint(graphics);
}
protected void onFocus(int direction)
{
focused = true;
}
protected void onUnfocus()
{
focused = false;
};
};

Please use plain text.
Developer
lakshman9687
Posts: 243
Registered: ‎07-22-2011
My Device: BlackBerry Z10
My Carrier: AirTel

Re: ButtonField Focus Color

[ Edited ]

Hi,

 

Try this once

 

ButtonField btn = new ButtonField("Test",ButtonField.USE_ALL_WIDTH|ButtonField.FIELD_HCENTER)
{
boolean focused = false;
protected void paint(Graphics graphics)
{
graphics.setColor(color);
graphics.setBackgroundColor(0x00D8632E );
super.paint(graphics);
}
protected void onFocus(int direction)
{
color = Color.WHITE;
invalidate();
}
protected void onUnfocus()
{
color = Color.BLACK;
invalidate();
};
};

 Regards,

Lakshman K

----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

Please use plain text.
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: ButtonField Focus Color

It does not work. Unable to set background color.
Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: ButtonField Focus Color

buttonfield does not support this, you would have to customize a field for that, or use a bitmapfield-button.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
shivam284
Posts: 108
Registered: ‎01-23-2012
My Device: torch,bold,curve,strom
My Carrier: Blackberry

Re: ButtonField Focus Color

For this you have to customized the button field.

Thanks & Regards,
Kumar Shivam
Please use plain text.
New Developer
saurabh0208
Posts: 10
Registered: ‎08-24-2012
My Device: 9820
My Carrier: Airtel

Re: ButtonField Focus Color

Just override the ApplyTheme method of button field.

and paint the desired background inPaint function.

Please use plain text.