0

我試圖通過修改發現的代碼here使用ActionBarSherlock在我的操作欄中實現取消/完成佈局。ActionBarSherlock - 未顯示預分頻器的分頻器

一切按ICS或Jelly Bean(其中ABS將使用本機ActionBar)的預期工作。

Gingerbread-missing-divider

我起初以爲這是與分離圖像的問題,但即使在使用時:當薑餅(API 10)測試,一切都只是分隔不按鍵之間出現工作正常喜歡碼:

android:divider="#f00" 

無隔離帶出現在薑餅,但鮮豔的紅色一個出現,符合市場預期,對ICS/JB。顯然,ActionBarSherlock 3.5+使用原生行爲來實現divider外觀,那麼爲什麼在使用ABS時divider不會出現,而是在使用原生ActionBar時出現?

這裏是我的XML:

actionbar_custom_view_done_discard.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:divider="?attr/dividerVertical" 
    android:dividerPadding="12dp" 
    android:orientation="horizontal" 
    android:showDividers="middle" > 

    <include layout="@layout/actionbar_cancel_button" /> 

    <include layout="@layout/actionbar_done_button" /> 

</LinearLayout> 

actionbar_cancel_button.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/actionbar_cancel" 
    style="?actionButtonStyle" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:background="@drawable/abs__item_background_holo_light" > 

    <TextView 
     style="?actionBarTabTextStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:drawableLeft="@drawable/ic_action_cancel" 
     android:drawablePadding="8dp" 
     android:gravity="center_vertical" 
     android:paddingRight="20dp" 
     android:text="@string/action_cancel" /> 

</FrameLayout> 

actionbar_done_button.xml是完全一樣的,但上面用名稱,文字和圖標已更改。

在此先感謝。

回答

6

LinearLayout中的分隔符是API 11+。這與ActionBarSherlock無關。

您可以簡單地在兩個元素之間添加一個帶背景的1dp視圖來解決此問題。

+0

啊,謝謝!那我就這樣做。 – Ellis 2013-03-17 20:52:10

1

這是我發現是定製ActionBar佈局的最佳實施:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" > 

<include layout="@layout/actionbar_cancel_button" /> 

<!-- View below is used because the android:divider attribute only works on API 11+. This is identical in appearance to that. --> 

<View 
    style="@style/Widget.Sherlock.Light.ActionButton" 
    android:layout_width="1dp" 
    android:layout_height="match_parent" 
    android:layout_marginBottom="12dp" 
    android:layout_marginTop="12dp" 
    android:background="@drawable/abs__list_divider_holo_light" /> 

<include layout="@layout/actionbar_done_button" /> 

+0

感謝分享,這比我的觀點更清潔。也許像我這樣發佈整個LinearLayout,以便人們可以複製和粘貼 – Maragues 2013-03-18 15:25:40

+0

它實際上來自[this](http://stackoverflow.com/a/15390898/2044848)答案,它使用layout-v11文件夾中的本地實現,並且佈局文件夾中的自定義佈局。它的工作,但我覺得這是不必要的重複。我將編輯我的答案以包含整個佈局。按鈕佈局在我的問題中描述。 – Ellis 2013-03-18 17:35:09

+0

你可以發佈你的其中一個操作欄按鈕的佈局代碼嗎?謝謝 – speedynomads 2013-04-18 12:43:05