0

私はpngといくつかの部分から透明なホバー画像を配置したカスタムImageButtonを持っています。そのため、フォーカスされると、青色のフォーカスでそれ自体も取得されます。そのフォーカスの青い色を削除したいのですが、同時に hoverImage を機能させたいです!
これは私の ImageButton クラスです: http://codepad.org/mjtIUKLR

4

1 に答える 1

2

私にとって有効な解決策は、この機能をペイント メソッドに追加し、フォーカスが得られたかどうかを追跡することです。

boolean hasFocus = false;
public void onFocus(int direction) {
    invalidate();
    hasFocus = true;
}

public void onUnfocus() {
    hasFocus = false;
    invalidate();
    super.onUnfocus();
}

そして、ペイントメソッドでこれを使用します:

public void paint(Graphics graphics) {
    if (hasFocus){
        graphics.drawShadedFilledPath(xPositions, yPositions, null,      
                                      HIGHLIGHTED_GRADIENT, null);
    }else{
        graphics.drawShadedFilledPath(xPositions, yPositions, null,      
                                      GRADIENT, null);      
    }
   super.paint(graphics);
}

上記の例では、ハイライトにデフォルトの青色をオーバーライドするカスタム グラデーションを使用しています。あなたの場合、明らかにイメージなどを変更したいと思うでしょう。

于 2013-01-29T14:48:32.037 に答える