Briefly hiding ActionBar without resizing Activity

后端 未结 1 1426
孤独总比滥情好
孤独总比滥情好 2021-01-02 15:47

I\'m using a ViewPager to scroll between different fragments. There are two types of fragments, using two different menu resources. I\'m invalidating the menu to switch betw

相关标签:
1条回答
  • 2021-01-02 16:11

    I didn't quite catch the menu part of your problem, but there is an easy solution to preventing your activity from resizing when the ActionBar appears or disappears.

    You can tell the ActionBar to draw itself in overlay mode, meaning it will float on top of the activity, in stead of actually being part of the activity's layout. Use either android:windowActionBarOverlay in your theme, or the Window.FEATURE_ACTION_BAR_OVERLAY flag from code.

    You probably want to use this feature in conjunction with the actionBarSize constant, that specifies the correct offset for the first view in your layout. This way, your content still appears below the ActionBar, but since the ActionBar itself is an overlay, upon hiding/showing it, the activity will not resize.

    <SomeView
        ...
        android:layout_marginTop="?android:attr/actionBarSize" />
    

    More details can be found in the documentation.

    0 讨论(0)
提交回复
热议问题