Android ActionBar was introduced from API level 11. In this example, I will show how to add simple android action bar tabs to your application. At last, I have provided GitHub link to download complete source code of this example project.

Android Material Design Sliding Tabs Example
Animated Android Folding Tab Bar Menu Example
Android Material Design Tabs Using TabLayout

Android ActionBar Tabs

Create a new Android Project

Application Name: ActionBar Tab Example
Company Domain: viralandroid.com
Package Name: com.viralandroid.actionbartabexample
Minimum SDK: Android 2.2 (API 8 Froyo)

Add Tabs to Your Activity

To add tabs in the action bar of your app, you have to implement ActionBar.TabListener in your java activity. And your java activity file looks like this.

Create Three XML Layout for Tabs

To show different content in different tabs, you have to create XML layout for different tabs. Following are the three XML activity layouts for three action bar tabs, actionbar_tab_1.xml for tab 1, actionbar_tab_2.xml for tab 2 and actionbar_tab_3.xml for tab 3.

And also, your main XML activity layout looks like this.

That’s all. Now run your application. The final result is shown below.

Android ActionBar Tabs Example
Android ActionBar Tabs

Download Complete Example Project

Download complete Android ActionBar Tabs Example project source code from GitHub.

Post a Comment

Powered by Blogger.