タイトルをアクションバーの中央に配置し、その横にアクションアイコンを配置したいと思います(重力設定ではそれらを無視します)。
これが欲しい:
代わりに私はこれを持っています:
これが私のコードです:
ActionBar actionBar = getSupportActionBar();
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.top_bar));
actionBar.setCustomView(LayoutInflater.from(this).inflate(R.layout.actionbar_layout, null), params);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
私のレイアウト:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="8dp"
android:src="@drawable/launcher_icon" />
<TextView
android:id="@+id/actionbar_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:maxHeight="1dp"
android:maxLines="1"
android:paddingLeft="48dp"
android:paddingRight="48dp"
android:text="Bacon ipsum"
android:textColor="#777777"
android:textSize="20sp" />
</RelativeLayout>
だから私の問題は、タイトルを中央に配置することだけが機能することです.0のアクションバーアイテムが隣にある場合、アイテムを追加するとすぐに中央揃えが台無しになります。それと一緒にアフォーダンスアップボタンを使用できれば、それも素晴らしいでしょう(これはまた、今ではセンタリングを台無しにします).
どんな助けでも大歓迎です。
独自のアクションバー アイテム/ボタン ロジックを実装したくありません。