Actionbarsherlock switch Actionbar Software overlay mode

I am using Actionbarsherlock for my application and I like to toggle the Actionbar overlap mode in my code. I have 2 Fragments (one is Mapview where I want a semi-transparent action bar), the other is a ListFragment where a solid action bar is required.

I tried

requestWindowFeature((int) Window.FEATURE_ACTION_BAR & ~Window.FEATURE_ACTION_BAR_OVERLAY);

      

the problem is that the requesting functions only work before the content is added.

i using this style to do a transparent action bar

<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>

      

is there a way to establish

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

      

to false inside Activity / Fragment?

+3


source to share


1 answer


Edit: Unfortunately this doesn't work for Actionbarsherlock and ListFragment from the compatibility pack. For some reason, the top border is added to the bottom border. Left and right margins work fine inside the LayoutListener.

Found a solution to this problem in Android Developer Example



// 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 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 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);
        }
    }
};

      

+3


source







All Articles