Làm cách nào để triển khai nút hình ảnh trong BlackBerry?Nút Hình ảnh trong BlackBerry
Trả lời
đây bạn đi, mã hoàn chỉnh:
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;
}
}
Cảm ơn bạn đã trả lời nhanh chóng và chính xác .... –
Tôi biết điều này sẽ trở lại một thời gian nhưng tôi cần thêm các phương thức này vào nhận được khoảng trống được bảo vệ làm việc này onFocus (hướng int) { \t this.setHighlight (true); \t super.onFocus (hướng); \t} \t protected void onUnfocus() { \t \t this.setHighlight (false); \t super.onUnfocus(); \t} –
nâng cao UI Gói Sử dụng của RIM.
này chứa một lĩnh vực BitmapButton và một số lượng lớn các công cụ giao diện người dùng hữu ích.
(Không nghi ngờ gì Reflogs ví dụ là tốt, nhưng tôi nghĩ rằng các nhà phát triển BB mới hạ cánh trên trang này các gói nâng cao giao diện người dùng là có lợi hơn)
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();
}
}
Cách đơn giản nhất để làm điều đó:
bước 1 : vẽ một hình ảnh với các tọa độ cụ thể (imageX, imageY). bước 2: thêm một phương pháp trong Mã của bạn:
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. Blackberry - cách đổi kích thước hình ảnh?
- 2. Công cụ chụp màn hình cho BlackBerry?
- 3. Cách tạo nút hình ảnh trong Android?
- 4. cách mã nút Hình ảnh trong PyQt?
- 5. hình ảnh nút thay đổi trong android
- 6. bộ hình ảnh như nút
- 7. hình ảnh cho AlertDialog nút
- 8. nút hình ảnh với html5
- 9. Làm cách nào tôi có thể kéo hình ảnh trong nút hình ảnh thành toàn bộ vùng của nút ảnh?
- 10. Sự khác biệt giữa nút hình ảnh và nút
- 11. Hình ảnh tùy chỉnh nút hủy UISearchbar
- 12. 'Graying Out' một hình ảnh nút WPF?
- 13. Java: Hình ảnh làm nút chuyển đổi
- 14. Highcharts: Thêm nút hình ảnh tùy chỉnh
- 15. Qt: tạo "nút hình ảnh svg"
- 16. Nút hình ảnh hiển thị 'Gửi truy vấn' phía trên cùng của hình ảnh trong Firefox
- 17. thiết kế bố trí như bên dưới hình ảnh với các nút hình ảnh trong android
- 18. Phương pháp hình ảnh nút cài đặt
- 19. hình ảnh cho nút Cancel của UISearchBar
- 20. Hình ảnh iOS quay trên nút bấm
- 21. Văn bản trên nút Hình ảnh trong C# asp.net 3.5
- 22. Thêm một hình ảnh bên trong một nút lập trình
- 23. Cách thêm văn bản dưới nút hình ảnh trong Android?
- 24. CSS - nút vị trí bên trong hình ảnh
- 25. Mẫu nút có hình ảnh và văn bản trong wpf
- 26. Tạo một nút hình ảnh trong .NET Ứng dụng Winforms
- 27. Nút Gửi hình ảnh trong một Biểu mẫu
- 28. Thêm một hình ảnh trong một nút WPF
- 29. Tạo nút tròn trong iOS7 mà không cần hình ảnh
- 30. Cách kiểm tra hình ảnh nút trong Xcode
Để tạo một nút hình ảnh BlackBerry Tuỳ chỉnh mà bạn có thể kiểm tra liên kết này [click vào đây] (http://www.javacodeone.blogspot.in/2012/10/ blackberry-custom-playpause-image-button.html) ở đây bạn có sẵn với mã nguồn đầy đủ với lời giải thích – String