1

背景が透明な画像ボタンを作成するにはどうすればよいですか?

デフォルトの背景は灰色です。空のテキストと setIcon を使用してボタンを作成しました。次のようになります。

    backButton = new Button(); //"Back");
    backButton.setIcon(backIcon);

    iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer).
            setStyles(make(VALIGN.top, HALIGN.right)).
            setBounds(0, 0, width, height).
            add(backButton);

しかし、API/ソースコードからボタンを透明にする方法を理解できませんでした。

ヘルプ/ヒントは大歓迎です。

4

1 に答える 1

2

を使用しますStyle.BACKGROUND

UI 全体のすべてのボタンの背景を空白にしたい場合は、ルート スタイルシートを次のように構成します。

Stylesheet ROOT = SimpleStyles.newSheetBuilder().
 add(Button.class, Styles.none().
   add(Style.BACKGROUND.is(new NullBackground())).
   addSelected(Style.BACKGROUND.is(new NullBackground()))).
 create();

Root root = iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer).etc().

特定のボタンの背景を空白にしたい場合は、ボタンで設定します。

Styles blankBg = Styles.none().
   add(Style.BACKGROUND.is(new NullBackground()))
   addSelected(Style.BACKGROUND.is(new NullBackground());

Button backButton = new Button().addStyles(blankBg).setIcon(backIcon);

SimpleStyles がボタンの背景を定義することにも注意してください。完全に空白のスタイルシートから開始する場合、ボタンの背景定義を省略でき、ボタンは空白になります。

于 2012-02-12T00:41:10.427 に答える