使用相對佈局時,ActionBar不顯示標題。 而當我不使用RelativeLayout時,這些項目沒有對齊到正確的位置。 請不要告訴我使用菜單項作爲解決方案。它必須是自定義的。帶有自定義RelativeLayout的ActionBarSherlock不顯示標題文本
這是我如何設置:
ActionBar bar = getSupportActionBar();
bar.setDisplayOptions(
ActionBar.DISPLAY_HOME_AS_UP |
ActionBar.DISPLAY_SHOW_CUSTOM |
ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE |
ActionBar.DISPLAY_USE_LOGO);
bar.setTitle(title);
bar.setCustomView(actionBar);
this.setTitle(title);
這是當對齊是好的,但標題沒有顯示
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true" >
<ImageButton
android:id="@+id/acion_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu_label_add"
style="?attr/actionButtonStyle" />
<ImageButton
android:id="@+id/action_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu_label_prev"
style="?attr/actionButtonStyle" />
<ImageButton
android:id="@+id/action_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu_label_next"
style="?attr/actionButtonStyle" />
</LinearLayout>
</RelativeLayout>
而且來這裏的佈局,其中的標題顯示,但項目對齊到左側
<?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="wrap_content"
android:layout_gravity="right"
android:gravity="right">
<ImageButton
android:id="@+id/acion_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu_label_add"
style="?attr/actionButtonStyle" />
<ImageButton
android:id="@+id/action_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu_label_prev"
style="?attr/actionButtonStyle" />
<ImageButton
android:id="@+id/action_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu_label_next"
style="?attr/actionButtonStyle" />
</LinearLayout>
我做了同樣的事情。不幸的是,這在RTL設備中無法正常工作。 – AsafK