how to set image background of button in Blackberry [duplicate] - blackberry

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Image Button in BlackBerry
i want set images as background of button. but i am not get any idea how it possible so can any one help me for my problem..
Thank you in advance..

You'll need to use a BitmapField, set it FOCUSABLE, and then override navigationClick() to execute the FieldChangeListener

Here's the link to official doc
http://docs.blackberry.com/en/developers/deliverables/29251/Creating_a_custom_button_1676236_11.jsp
I think it has everything you need plus it will let you know about creating custom objects

You have to make a custom field that will contain a bitmap and that will handle the click event or use the BitmapField and set the FOCUSABLE style to it. If you need help in how to create custom fields let me know..

It is possible.
image=Bitmap.getBitmapResource("abc.png");
one=new ButtonField("One")
{
protected void paint(Graphics g)
{
g.drawBitmap(0, 0, image.getWidth(), image.getHeight(), image, 0, 0);
super.paint(g);
}
};
one.setChangeListener(this);
hor.add(one);

Related

Search bar on top of the mainscreen blackberry

I want to make one search bar on top of the mainscreen and this search bar should include one editfield and one image of search icon.
Please help me...
Thanks, in advance
You need to use an HorizontalFieldManager to put editfield and image on the same line. Read here http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/ui/container/HorizontalFieldManager.html and here: http://www.androidadb.com/class/ho/HorizontalFieldManager.html , a simple example showing how adding two buttons in an HorizontalFieldManager. Just substitute buttons with yor needed fields.
Or you can play with GridFieldMgr:
GridFieldManager gridMgr_g = new GridFieldManager(1, 2, 0);
gridMgr_g.setColumnProperty(0, GridFieldManager.FIXED_SIZE, screenWidth-myBitmapRes.width);
gridMgr_g.setColumnProperty(1, GridFieldManager.FIXED_SIZE, myBitmapRes.width);
gridMgr_g.add(new EditField());
gridMgr_g.add(new BitmapField(Bitmap.getBitmapResource(myBitmapRes)));
add(gridMgr_g);

Blackberry Custom ButtonField with no Border

how could i create a custom ButtonField with no border in Blackberry...
any help will be appreciated
bingo, just add the applyTheme() method
class BitmapButtonField extends ButtonField {
protected void applyTheme()
{
}
}
Arhimed & Rafael, thanks for you help!
Use this tutorial to create your own custom field.
Control the appearance of your field in paint() method.
Yes, this is possible by extending Field. You just need to create 2 images (one for a focused state and one for an unfocused state). Just don't draw the border on those images.
A sample implementation can be found here.
As Arhimed said, you should extend Field. This will give you the maximum amount of customization over how the button looks.
Here's an example of a customizable button I've created: https://github.com/HeshamMegid/BlackBerry-Custom-Controls
You could use it as it is or modify the code further to suit your needs.

How to set non focusable labelField inside a GridField

I have developed a application with considering touch screen device for BlackBerry.
But when I am trying to use it in Non touch screen device all the lable also shows the focus.
Basically what I want that LabelField should not show any focus.
I have set NonFocusable Property for it but still it is not working.
Please help me out.
Thanks in advance...
You dont want the LabelField to have focus when you select it on touchscreen ?
Extend LabelField and override onFocus like so -
protected void onFocus(int direction) {
}
Also try overriding the LabelField's isFocusable() to always return false. It's possible that the GFM is just calling setFocus() on the next field without checking whether or not it can actually accept focus. If this is the case you may have to override the GFM's nextFocus() method and correct the logic.

BlackBerry: TreeField with BitmapField

I want to display the contacts in a TreeField like:
An image followed by a username
My understanding is that I use a BitmapField to display the image, but I don't see how to combine a BitmapField with a TreeField.
You can't use another field with a TreeField. You need to implement the TreeFieldCallback.drawTreeItem() method and do the drawing yourself
See my answer to a similar StackOverflow question: "Customising Blackberry Treefield."
In that answer, I've re-drawn each row of a TreeField along with a Bitmap image replacing the default (+)-icon of TreeField.
You can do it by using graphics.drawBitmap() method and graphics.drawText() method and using the index and y parameters inside the drawTreeItem() method of class which implements TreeFieldCallback interface

Hightlight image within a vertical manager

So i have 3 images in a vertical field manager and each image is clickable and proceeds to the correct url. all that works. the only problem at this time is that when i scroll (up or down), i don't know which image is currently focused. i don't know until the browser opens the corresponding url.
so is there any way to get a border or a highlight to appear under my images (or within the manager) so that i can definitely see which image is currently focused? so if you think of a list, your selections are highlighted as you scroll up and down. i want something similar to that with my application.
thank you for your help.
ac
using the setSpace(int,int) method on the bitmap field worked great. this allowed me to see a border around the element that had focus.
override inline the bitmapfield drawFocus method. Something like this
protected void drawFocus(Graphics graphics, boolean on){
graphics.setBackgroundColor(0x00204020);
graphics.drawRect(0, 0, getBitmapWidth(), getBitmapHeight());
}

Resources