アクションバーシャーロックを使用しています。
下部にアクションモードを取得するために(下部にアクションモード)を使用します
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 つは、ボタンの背景の色をアクションバーの色と同じにすることです。これは透明に見えますが、良い解決策ではないと思います。