黑莓 - 将图像添加到按钮?

时间:2012-10-10 12:03:25

标签: button blackberry blackberry-jde

就像我想要自定义它一样。我已经提供了一个图像,我想在登录按钮上设置它。

我试过Login.setBackground(“loginbackground.png”);但它没有符合我的要求。这个问题有重复,但我没有找到一个完美的解决方案,这就是发布它的原因:S

感谢。

1 个答案:

答案 0 :(得分:1)

如果您想在后台添加图片到按钮,请使用以下代码尝试:

Bitmap bitmap = Bitmap.getBitmapResource("rectangle.png");
Background background = BackgroundFactory.createBitmapBackground(bitmap);
button1 = new ButtonField("Button1", ButtonField.USE_ALL_WIDTH);
button1.setBackground(background);
add(button1);

或者你可以通过以下方式添加图像并添加点击功能来实现:

Bitmap msg = Bitmap.getBitmapResource("msg.png");
BitmapField message = new BitmapField(msg, Field.FOCUSABLE)
{
    protected boolean navigationClick(int status,int time)
    {
        label.setText("Messages");
        Dialog.alert("Message icon selected");
        return true;
    }
};
add(message)