0

アクションバーシャーロックを使用しています。

下部にアクションモードを取得するために(下部にアクションモード)を使用します

android:uiOptions="splitActionBarWhenNarrow"

しかし、メインのアクション バーにボタンを追加する必要があるため、カスタム ビューを使用します。

    View customNav = LayoutInflater.from(this).inflate(R.layout.custom_view, null);      
    getSupportActionBar().setCustomView(customNav, new 
         ActionBar.LayoutParams(Gravity.RIGHT));
    getSupportActionBar().setDisplayShowCustomEnabled(true);

これがcustom_view.xmlです

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="horizontal"
>

<ImageButton
    android:id="@+id/btnMore"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_action_day"
    android:onClick="onMoreClick"/>

同じプロパティで ImageButton や ImageView を使用しても意味がないので、ImageButton について説明します。

ImageButton を使用すると、背景が灰色であることを除いて、必要なものが得られます。 ここに画像の説明を入力

前のcustom_view.xmlに行を追加すると、透明な背景を取得する(または代わりにImageViewを使用する)

android:background="#00000000"

アイコンのアルファが「トリミング」され、ボタンのサイズが変更されます。 ここに画像の説明を入力

質問は。最初の画像(デフォルトの灰色の背景)のようなサイズのボタンを透明な背景で取得するにはどうすればよいですか?

問題を解決する方法の 1 つは、ボタンの背景の色をアクションバーの色と同じにすることです。これは透明に見えますが、良い解決策ではないと思います。

4

3 に答える 3

0

背景が透明な画像を使用できます。フォトショップでできます。

于 2012-10-15T19:15:04.870 に答える
0

ボタンに追加できると思います

android:background="yourimagethere"; または多分 android:background=NULL

そしてそれは問題を解決します

于 2013-05-15T12:15:12.007 に答える
0

ImageButton の代わりに ImageView を使用することを検討しましたか? ImageView に必要な画像を設定し、ImageButton の場合と同じように onclicklistener を使用してクリックを検出するだけです。

さらに、ImageButton の幅を指定し、必要に応じてパディングを設定することもできます (これは、android:background="#00000000" を使用する場合です)。

于 2012-10-15T21:04:39.777 に答える