【问题标题】:Blackberry Custom Image button黑莓自定义图像按钮
【发布时间】:2012-09-15 04:17:57
【问题描述】:

我创建了一个自定义图像按钮;一个是播放图片按钮,一个是暂停图片按钮。

我想在播放暂停之间切换(即当用户点击按钮时,它必须改变 - 播放暂停或暂停播放)。

对于我的要求,我参考了这个example url

当我执行我的程序时,我可以显示按钮,但是当我点击按钮时,我无法更改图像按钮(播放暂停)

谁能帮帮我?

【问题讨论】:

    标签: blackberry java-me


    【解决方案1】:

    您正在处理的示例使用两个图像,onoff 图像。但是,它使用这两个图像来根据按钮是否具有 focus 来更改按钮的外观。

    你想要一些不同的东西。您希望在按钮被单击 时更改按钮的外观。为此,您可以使用此现有方法:

    protected boolean navigationClick(int status, int time){
        fieldChangeNotify(1);
        return true;
    }
    

    为此,更改(或添加)一些成员变量来存储播放和暂停位图,然后更改navigationClick() 以在它们之间切换:

    private Bitmap _currentPicture;
    private Bitmap _playPicture;
    private Bitmap _pausePicture;
    
    protected boolean navigationClick(int status, int time){
        if (_currentPicture == _playPicture) {
            _currentPicture = _pausePicture;
        } else {
            _currentPicture = _playPicture;
        }
        invalidate();  // may be necessary to force redraw of the button
    
        fieldChangeNotify(1);
        return true;
    }
    

    编辑:您可能还想在trackwheelClick()keyChar() 方法中执行相同的逻辑(如上面navigationClick()),具体取决于您的按钮是否应该是也可以使用拨轮或输入键单击See an example of that here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多