Comment implémenter un bouton d'image dans BlackBerry?Bouton Image dans BlackBerry
Répondre
ici vous allez, le code complet:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ButtonField;
/**
* Button field with a bitmap as its label.
*/
public class BitmapButtonField extends ButtonField {
private Bitmap bitmap;
private Bitmap bitmapHighlight;
private boolean highlighted = false;
/**
* Instantiates a new bitmap button field.
*
* @param bitmap the bitmap to use as a label
*/
public BitmapButtonField(Bitmap bitmap, Bitmap bitmapHighlight) {
this(bitmap, bitmapHighlight, ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER);
}
public BitmapButtonField(Bitmap bitmap, Bitmap bitmapHighlight, long style) {
super(style);
this.bitmap = bitmap;
this.bitmapHighlight = bitmapHighlight;
}
/* (non-Javadoc)
* @see net.rim.device.api.ui.component.ButtonField#layout(int, int)
*/
protected void layout(int width, int height) {
setExtent(getPreferredWidth(), getPreferredHeight());
}
/* (non-Javadoc)
* @see net.rim.device.api.ui.component.ButtonField#getPreferredWidth()
*/
public int getPreferredWidth() {
return bitmap.getWidth();
}
/* (non-Javadoc)
* @see net.rim.device.api.ui.component.ButtonField#getPreferredHeight()
*/
public int getPreferredHeight() {
return bitmap.getHeight();
}
/* (non-Javadoc)
* @see net.rim.device.api.ui.component.ButtonField#paint(net.rim.device.api.ui.Graphics)
*/
protected void paint(Graphics graphics) {
super.paint(graphics);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Bitmap b = bitmap;
if (highlighted)
b = bitmapHighlight;
graphics.drawBitmap(0, 0, width, height, b, 0, 0);
}
public void setHighlight(boolean highlight)
{
this.highlighted = highlight;
}
}
Merci pour la réponse rapide et précise .... –
Je sais que cela remonte à un certain temps, mais j'avais besoin d'ajouter ces méthodes à obtenir ce vide protégé par le travail onFocus (direction int) { \t this.setHighlight (true); \t super.onFocus (direction); \t} \t { \t onUnfocus protected void() \t this.setHighlight (false); \t super.onUnfocus(); \t} –
UI Advanced Pack Utilisons RIM.
Il contient un champ BitmapButton et un grand nombre d'outils de l'interface utilisateur utiles.
(sans doute Reflogs exemple est bon, mais je pense que pour les nouveaux développeurs BB atterrissage sur cette page le pack interface utilisateur avancée est plus avantageux)
perfect ImageButton for Blackberry , According to user point of view a Imagebutton should have four states
1. Normal
2. Focus
3. Selected Focus
4. Selected unfocus
the Following code maintain all four states (Field-Change-Listener and Navigation)
if you want to maintain all four states than use 1st Constructor, If you just want to handle Focus/Un-Focu state of the button than use 2nd one
########################################
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
public class ImageButton extends Field
{
Bitmap mNormalIcon;
Bitmap mFocusedIcon;
Bitmap mActiveNormalIcon;
Bitmap mActiveFocusedIcon;
Bitmap mActiveBitmap;
String mActiveText;
int mHeight;
int mWidth;
boolean isStateActive = false;
boolean isTextActive = false;
public boolean isStateActive()
{
return isStateActive;
}
public ImageButton(Bitmap normalIcon, Bitmap focusedIcon)
{
super(Field.FOCUSABLE | FIELD_VCENTER);
mNormalIcon = normalIcon;
mFocusedIcon = focusedIcon;
mActiveBitmap = normalIcon;
mActiveFocusedIcon = focusedIcon;
mActiveNormalIcon = normalIcon;
// isTextActive = false;
}
public ImageButton(Bitmap normalIcon, Bitmap focusedIcon, Bitmap activeNormalIcon, Bitmap activeFocusedIcon)
{
super(Field.FOCUSABLE | FIELD_VCENTER);
mNormalIcon = normalIcon;
mFocusedIcon = focusedIcon;
mActiveFocusedIcon = activeFocusedIcon;
mActiveNormalIcon = activeNormalIcon;
mActiveBitmap = normalIcon;
// isTextActive = true;
}
protected void onFocus(int direction)
{
if (!isStateActive)
{
mActiveBitmap = mFocusedIcon;
}
else
{
mActiveBitmap = mActiveFocusedIcon;
}
}
protected void onUnfocus()
{
super.onUnfocus();
if (!isStateActive)
{
mActiveBitmap = mNormalIcon;
}
else
{
mActiveBitmap = mActiveNormalIcon;
}
}
protected boolean navigationClick(int status, int time)
{
mActiveBitmap = mActiveNormalIcon;
toggleState();
invalidate();
fieldChangeNotify(1);
return true;
}
public void toggleState()
{
isStateActive = !isStateActive;
}
public int getPreferredWidth()
{
return mActiveBitmap.getWidth() + 20;
}
public int getPreferredHeight()
{
return mActiveBitmap.getHeight() + 10;
}
protected void layout(int width, int height)
{
mWidth = getPreferredWidth();
mHeight = getPreferredHeight();
setExtent(mWidth, mHeight);
}
protected void paint(Graphics graphics)
{
graphics.drawBitmap(0, 5, mWidth, mHeight, mActiveBitmap, 0, 0);
// graphics.setColor(0xff0000);
// graphics.drawText(mActiveText, (mActiveBitmap.getWidth() -
// this.getFont().getAdvance("ON"))/2, mActiveBitmap.getHeight());
}
protected void drawFocus(Graphics graphics, boolean on)
{
}
public void activate()
{
mActiveBitmap = mActiveNormalIcon;
isStateActive = true;
invalidate();
}
public void deactivate()
{
mActiveBitmap = mNormalIcon;
isStateActive = false;
invalidate();
}
}
meilleure façon de le faire:
étape 1 : dessine une image avec des coordonnées spécifiques (imageX, imageY). étape 2: ajouter une méthode dans votre code:
void pointerControl(int x, int y) {
if (x>imageX && x<imageX+imageName.getWidth() && y>imageY && y < imageY+imageName.getHeight) {
//to do code here
}
}
where imageName:name of image
imageX=x coordinate of image(Top-Left)
imageY=y coordinate of image(Top-Left)
- 1. Image sur fond Image dans Blackberry
- 2. Boutons image BlackBerry
- 3. BlackBerry - image 3D transformer
- 4. Image dans le bouton GWT
- 5. Bouton WPF avec image
- 6. ensemble image bouton d'envoi
- 7. Blackberry: Télécharger et afficher .jpg image
- 8. Bouton Image Problème
- 9. Problème avec l'action du bouton sur BlackBerry
- 10. Image sur un bouton
- 11. Bouton WPF TriState Image
- 12. Android Image bouton fondu
- 13. Bouton GWT (Image + Texte)
- 14. Blackberry - Petit Haut Bas Bouton Flèche
- 15. Bouton Image dans le champ de recherche?
- 16. Comment enregistrer et supprimer une image Bitmap dans Blackberry Storm?
- 17. Comment rendre une image aussi transparente dans BlackBerry?
- 18. jpeg image prenant beaucoup de temps à charger dans blackberry
- 19. image en bouton: espace étrange
- 20. Android - Taille du bouton Image
- 21. iphone: Bouton/Image sur TabBarController?
- 22. Formulaire Bouton Image Mouseover Options
- 23. jQuery bouton image newbie question
- 24. Boutons dans Blackberry
- 25. BlackBerry - Comment définir une image comme arrière-plan pour ButtonField?
- 26. Blackberry - getPreferredWidth ignoré dans 4.5?
- 27. Blackberry "périphérique arrière" bouton met fin à l'application
- 28. Est-il possible de mettre une image d'une URL dans un bouton image dans Android?
- 29. Ajouter un bouton à une image
- 30. à quoi sert le bouton image?
Pour créer un bouton d'image personnalisée BlackBerry vous pouvez vérifier ce lien [cliquez ici] (http://www.javacodeone.blogspot.in/2012/10/ blackberry-custom-playpause-image-button.html) ici vous êtes disponible avec le code source complet avec l'explication – String