2012-09-15 241 views
2

我已經創建了自定義圖像按鈕;一個是播放圖像按鈕和一個是暫停圖像按鈕。黑莓自定義圖像按鈕

我想改用之間發揮暫停(即當用戶點擊按鈕,就必須改變 - 玩暫停或暫停播放)。

對我的要求,我已經提到了這個example url

當我執行我的計劃,我能夠顯示的按鈕,但是當我點擊按鈕,我不能夠改變的ImageButton(播放暫停)

任何人都可以幫我嗎?

回答

2

您正在處理的示例使用兩張圖像關閉圖像。但是,它使用這兩個圖像來根據按鈕是否具有焦點來改變按鈕的外觀。

你想要的東西有點不同。當按鈕變爲點擊時,您想要更改按鈕的外觀。要做到這一點,你可以使用這個現有的方法:

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; 
} 

編輯:你可能也想(在navigationClick()如上)在trackwheelClick()keyChar()方法來執行相同的邏輯,這取決於你是否按鈕應該是通過撥輪或輸入鍵也可點擊See an example of that here