How to make a ActionBar like Google Play that fades in when scrolling

前端 未结 8 862
-上瘾入骨i
-上瘾入骨i 2020-11-27 09:06

How to make transparent or translucent ActionBar like Google Play that fades in or out when scrolling using windowActionBarOverlay?

Check the f

相关标签:
8条回答
  • 2020-11-27 09:51

    Official Google DeveloperDocumentation

    enter image description here

    action bar in overlay mode.

    Enable Overlay Mode

    To enable overlay mode for the action bar, you need to create a custom theme that extends an existing action bar theme and set the android:windowActionBarOverlay property to true.

    For Android 3.0 and higher only

    If your minSdkVersion is set to 11 or higher, your custom theme should use Theme.Holo theme (or one of its descendants) as your parent theme. For example:

    <resources>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActionBarTheme"
               parent="@android:style/Theme.Holo">
            <item name="android:windowActionBarOverlay">true</item>
        </style>
    </resources>
    

    For Android 2.1 and higher

    If your app is using the Support Library for compatibility on devices running versions lower than Android 3.0, your custom theme should use Theme.AppCompat theme (or one of its descendants) as your parent theme. For example:

    <resources>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActionBarTheme"
               parent="@android:style/Theme.AppCompat">
            <item name="android:windowActionBarOverlay">true</item>
    
            <!-- Support library compatibility -->
            <item name="windowActionBarOverlay">true</item>
        </style>
    </resources>
    

    Specify Layout Top-margin

    When the action bar is in overlay mode, it might obscure some of your layout that should remain visible. To ensure that such items remain below the action bar at all times, add either margin or padding to the top of the view(s) using the height specified by actionBarSize. For example:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="?android:attr/actionBarSize">
        ...
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-11-27 09:58

    Please check this library https://github.com/ManuelPeinado/FadingActionBar which implements the cool fading action bar effect that you want

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