Skip to content
Related Articles

Related Articles

Improve Article

How to Use FadingActionBar Library in Android App?

  • Last Updated : 11 Jul, 2021
Geek Week

FadingActionBar is a library that implements a nice fading action bar effect. ActionBar fades gradually as we start scrolling down and turns completely opaque when scrolled above. It also supports the three most commonly used action bar implementations: stock (API 11+), ActionBarSherlock, and ActionBarCompat. In this article, we will be implementing this library in an Android App using Java language. A sample GIF is given below to get an idea about what we are going to do in this article. 

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add the library dependency 

Navigate to the Gradle Scripts > build.gradle(Module:app), add the library in the dependencies section, and sync the project.

dependencies {
    implementation 'com.github.manuelpeinado.fadingactionbar:fadingactionbar:3.1.2'

Step 3: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and refer to the following code. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
<!--activity_main contains the layout below action bar-->
    android:orientation="vertical" >
        android:textAppearance="@android:style/TextAppearance.Medium" />

Step 4: Working with the styles.xml file

Navigate to the app > res > values > styles.xml and refer to the following code. Below is the code for the styles.xml file. 


    <!-- Base application theme. -->
    <style name="Widget" />
    <style name="Widget.ActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse" />
    <style name="Widget.Light" />
    <style name="Widget.Light.ActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid" />
    <!--Transparent background-->
    <style name="Widget.ActionBar.Transparent">
        <item name="android:background">@android:color/transparent</item>
    <style name="Widget.Light.ActionBar.Transparent">
        <item name="android:background">@android:color/transparent</item>

Step 5: Working with the themes.xml file

  • Navigate to the app > res > values
  • Right-click on values and select New > Values Resource File
  • A dialog box will appear now, then add the File Name as themes and press OK.
  • Below is the code for the themes.xml file.


<?xml version="1.0" encoding="utf-8"?>
    <style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/Widget.ActionBar</item>
      <!-- Making the ActionBar Translucent-->
    <style name="AppTheme.TranslucentActionBar">
        <item name="android:actionBarStyle">@style/Widget.ActionBar.Transparent</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowContentOverlay">@null</item>
    <style name="AppTheme.Light.TranslucentActionBar" 
        <item name="android:actionBarStyle">
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowContentOverlay">@null</item>

Step 6: Working with the header.xml file

  • Navigate to the app > res > layout
  • Right-click on layout and select New > Layout Resource File
  • A dialog box will appear now, then add the File Name as header and press OK.
  • Below is the code for the header.xml file.


<?xml version="1.0" encoding="utf-8"?>
<!-- Header image -->
    android:src="@drawable/gfglongpng" />
<!--Add header image source in android:src-->

Step 7: Working with the AndroidManifest.xml file

Navigate to app > manifests > AndroidManifests.xml  and add the Translucent Theme inside the MainActivity tag. 


Step 8: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import com.manuelpeinado.fadingactionbar.FadingActionBarHelper;
// extend the MainActivity to Activity
// instead of AppCompatActivity
public class MainActivity extends Activity {  
    protected void onCreate(Bundle savedInstanceState) {
        // Adding FadingActionBar in the Activity
        FadingActionBarHelper helper = new FadingActionBarHelper()
                // actionBarBackground sets the background
                  // of actionBar in collapsed form
                // headerLayout sets the header layout of 
                  // actionBar in expanded form
                // contentLayout sets the main 
                  // content below action bar


GitHub Repository: Fading Action Bar Library

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!

My Personal Notes arrow_drop_up
Recommended Articles
Page :