How to make Android tab layout

Android tab layout

Here we demonstrate article about how to build Android tab layout with image and text.
Android tab layout example

Download Code Download APK

Let’s get started with eclipse IDE.

  • Create new project-> File->New -> Android Project and give activity AndroidTabActivity.
  • Open your AndroidTabActivity and extend TabActivity.
AndroidTabActivity.java


Create 4 class in src folder that extend activity and give name according to follow HomeActivity, MoreActivity, AccountActivity, SearchActivity, and type following code respectively.

HomeActivity.java

SearchActivity.java

AccountActivity.java

MoreActivty.java

Here we need three dimension of each icon so i have design each icon in 48 x 48px and then place into drowable hdpi folder you have to design each icon according to other drawable folder.

Now for 4 icons we need the icon state configuration files that define how to change state of icon. So create three 4 xml files in drawable directory. Type the following code.

account_icon_tab.xml

home_icon_tab.xml

more_icon_tab.xml

search_icon_tab.xml

activity_main.xml
  • open your activity_main file in folder res-> layout and code as following.

Now create 4 Layout respectively according to our activity. account_layout.xml, home_layout.xml, more_layout.xml, search_layout.xml, and type following code.

home_layout.xml

search_layout.xml

account_layout.xml

more_layout.xml

Now All ok and one final things have to do define all activity in AndroidManifest file, as listed bellow.

AndroidManifest.xml

finally run Android tab layout project using Run As-> Android Application.