Android Actionbar夏洛克开关Actionbar覆盖模式编程

Android Actionbar夏洛克开关Actionbar覆盖模式编程,android,android-layout,actionbarsherlock,Android,Android Layout,Actionbarsherlock,我的应用程序使用Actionbarsherlock,我喜欢在代码中切换Actionbar覆盖模式。 我有两个片段(一个是Mapview,我想要一个半透明的Actionbar),另一个是ListFragment,需要一个实心Actionbar 我试着 requestWindowFeature((int) Window.FEATURE_ACTION_BAR & ~Window.FEATURE_ACTION_BAR_OVERLAY); 问题是,请求功能只在添加内容之前起作用 我使用这种风格来

我的应用程序使用Actionbarsherlock,我喜欢在代码中切换Actionbar覆盖模式。 我有两个片段(一个是Mapview,我想要一个半透明的Actionbar),另一个是ListFragment,需要一个实心Actionbar

我试着

requestWindowFeature((int) Window.FEATURE_ACTION_BAR & ~Window.FEATURE_ACTION_BAR_OVERLAY);
问题是,请求功能只在添加内容之前起作用

我使用这种风格来完成透明的Actionbar

<style name="TransparentActionbar" parent="@style/Theme.Sherlock" xmlns:android="http://schemas.android.com/apk/res/android">
    <item name="windowActionBarOverlay">true</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="abBackground">#96000000</item>
    <item name="abDivider">@null</item>
</style>

真的
真的
#96000000
@空的
有什么方法可以设置吗

<item name="windowActionBarOverlay">true</item>
<item name="windowActionModeOverlay">true</item>
true
真的

在Activity/Fragment中是否为false?

编辑:遗憾的是,它不适用于Actionbarsherlock和兼容包中的ListFragment。 出于某种原因,将上边距添加到下边距。左右边距在LayoutListener中工作良好

找到了一个解决这个问题的方法


很好的发现,正是我需要的。对于阅读者来说,还有一件事:在示例中,他们还从
onDestroyView()
中的
ViewTreeObserver
中删除了
OnGlobalLayoutListener
。如下所示:
getListView().getViewTreeObserver().RemoveGlobalOnlyOutliner(MLayOutliner)可能很重要。
// Attach a GlobalLayoutListener so that we get a callback when the layout
// has finished drawing. This is necessary so that we can apply top-margin
// to the ListView in order to dodge the ActionBar. Ordinarily, that's not
// necessary, but we've set the ActionBar to "overlay" mode using our theme,
// so the layout does not account for the action bar position on its own.
ViewTreeObserver observer = getListView().getViewTreeObserver();
observer.addOnGlobalLayoutListener(layoutListener);

// Because the fragment doesn't have a reliable callback to notify us when
// the activity's layout is completely drawn, this OnGlobalLayoutListener provides
// the necessary callback so we can add top-margin to the ListView in order to dodge
// the ActionBar. Which is necessary because the ActionBar is in overlay mode, meaning
// that it will ordinarily sit on top of the activity layout as a top layer and
// the ActionBar height can vary. Specifically, when on a small/normal size screen,
// the action bar tabs appear in a second row, making the action bar twice as tall.
ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        int barHeight = getActivity().getActionBar().getHeight();
        ListView listView = getListView();
        FrameLayout.LayoutParams params = (LayoutParams) listView.getLayoutParams();
        // The list view top-margin should always match the action bar height
        if (params.topMargin != barHeight) {
            params.topMargin = barHeight;
            listView.setLayoutParams(params);
        }
        // The action bar doesn't update its height when hidden, so make top-margin zero
        if (!getActivity().getActionBar().isShowing()) {
          params.topMargin = 0;
          listView.setLayoutParams(params);
        }
    }
};