Tablayout Android Studio With Different Actionbar/Toolbar MenuItems For Different Fragments

We will learn about tablayout android studio example.

Tablayout android studio tutorial will guide you to make different actionbar/toolbar menuitems for different colors.

In whatsapp, when you slide fragments menu items are also changing. We will develop this functionality in tablayout android tutorial.

If you don’t have go through basic tablayout tutorial, then visit android tablayout tutorial.

You can make Custom Tablayout In Android with customizable tab name, tab color and various relative positions between tab name and tab icon.

Develop basic tablayout example from above link then follow steps of this tutorial.

First, check the output of this example.

Download Source Code for Tablayout Android example

[sociallocker]Download TabMenuItemDemonuts [/sociallocker]

Step 1: Creating Base Project

Follow all the steps from basic tablayout Android tutorial.

After you have completed above tutorial, you will have one android project with simple tablayout.

Now follow below steps.

Step 2: Adding images to drawable

Download images and copy them into “drawable” directory

TabMenu Icons

Step 3: Updating styles.xml

Update styles.xml file as per below source code

Step 4: Creating toolbar.xml file

Create a new resource file named toolbar.xml and paste below

Step 5: Developing OneActivity

Create a new activity named “OneActivity.”

Copy following in activity_one.xml

Add following source code into class

Step 6: Creating menu resource directory

Create a new resource directory named “menu” inside the “res” directory as per below image.

tablayout android

Inside “menu,” make three new xml files and name them as one_menu.xml,two_menu.xml and three_menu.xml

Add below source code in one_menu.xml

Add following in two_menu.xml

Add below in three_menu.xml

Step 7: Updating all fragments

Update as per below code

Update as per following

Update like below

Kotlin Version

Kotlin version of this example : Tablayout Kotlin Android

Feel free to use comment section for queries and reviews.

Thank you and share our tutorials with others to help them in their learnings.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

4 Responses

  1. hina says:

    i want to know its coding

  2. Dugange says:

    when I click 1. One button,
    an app responds with “Unfortunately, My application has stopped”

Leave a Reply

Your email address will not be published. Required fields are marked *