我应用自定义View的ActionBar,像这样的
// Inflate the "Done/Discard" custom ActionBar view.
LayoutInflater inflater = (LayoutInflater) DetailsHost.mActionBar
.getThemedContext().getSystemService(DetailsHost.LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(
R.layout.actionbar_custom_view_done_discard, null);
// Show the custom ActionBar view and hide the normal Home icon and title.
DetailsHost.mActionBar.setDisplayOptions(
ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_SHOW_TITLE);
DetailsHost.mActionBar.setCustomView(customActionBarView,
new ActionBar.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
Run Code Online (Sandbox Code Playgroud)
(基于Roman Nuriks代码).
如何恢复初始布局?注意:我使用ActionBarSherlock
我正在尝试使用ActionBarSherlock在我的操作栏中通过调整此处的代码来实现取消/完成布局.
一切都按照预期在ICS或Jelly Bean上运行(ABS将使用本机ActionBar).在Gingerbread(API 10)上进行测试时,除了按钮之间没有显示分隔符外,一切正常:

我起初认为这是分频器图像的问题,但即使使用如下代码:
android:divider="#f00"
Run Code Online (Sandbox Code Playgroud)
Gingerbread上没有出现分隔符,但正如预期的那样,在ICS/JB上出现了一个鲜红色的分隔符.显然,ActionBarSherlock 3.5+使用本机行为进行分隔符外观,那么为什么在使用ABS时分隔符不会出现但在使用本机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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
actionbar_done_button.xml与上面的完全相同,但更改了名称,文本和图标.
提前致谢.
xml android android-layout actionbarsherlock android-actionbar