TabHost 4


 

  1. TabHost with FragmentTabHost
  2. FragmentTabHost at Bottom
  3. FragmentTabHost with Only Images
  4. FragmentTabHost Customizing
  5. Swipeable TabHost with ViewPager

 

1. TabHost with FragmentTabHost
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open res -> layout ->Create new xml file, tab1_view.xml and add following code :

Step 5 : Open src -> package ->Create new class, Tab1Fragment.java and add following code (Note: Create two more classes and xml file, named Tab2Fragment.java and Tab3Fragment.java, as I’m skipping those because of shorting this tutorial and they are nothing but similar to Tab1Fragment.java. In your case, you might be using three different classes to achieve this.) :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:
tab_frag tab_frag2
Download SourceCode

 

2. FragmentTabHost at Bottom
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open res -> layout ->Create new xml file, tab1_view.xml and add following code :

Step 5 : Open src -> package ->Create new class, Tab1Fragment.java and add following code (Note: Create two more classes and xml file, named Tab2Fragment.java and Tab3Fragment.java, as I’m skipping those because of shorting this tutorial and they are nothing but similar to Tab1Fragment.java. In your case, you might be using three different classes to achieve this.) :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:
tab_btm tab_btm2
Download SourceCode

 

3. FragmentTabHost with Only Images
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open res -> layout ->Create new xml file, tab1_view.xml and add following code :

Step 5 : Open src -> package ->Create new class, Tab1Fragment.java and add following code (Note: Create two more classes and xml file, named Tab2Fragment.java and Tab3Fragment.java, as I’m skipping those because of shorting this tutorial and they are nothing but similar to Tab1Fragment.java. In your case, you might be using three different classes to achieve this.) :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:
tab_image tab_image2
Download SourceCode

 

4. FragmentTabHost Customizing
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open res -> layout ->Create new xml file, tab1_view.xml and add following code :

Step 5 : Open src -> package ->Create new class, Tab1Fragment.java and add following code (Note: Create two more classes and xml file, named Tab2Fragment.java and Tab3Fragment.java, as I’m skipping those because of shorting this tutorial and they are nothing but similar to Tab1Fragment.java. In your case, you might be using three different classes to achieve this.) :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:
tab_custom tab_custom2
Download SourceCode

 

5. Swipeable TabHost with ViewPager

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open res -> layout -> Create new xml, first_frag.xml and add following code :

Step 4 : Open src -> package -> MainActivity.java and add following code :

Step 5 : Open src -> package -> Create new class ViewPagerAdapter.java and add following code :

Step 6 : Open src -> package -> Create new class SlidingTabLayout.java and add following code :

Step 7 : Open src -> package -> Create new class SlidingTabStrip.java and add following code :

Step 8 : Open src -> package -> Create new class FirstFragment.java and add following code :

Step 9 : Open AndroidManifest.xml and add following code :

Step 10 : Open build.gradle (Module: app) file and add following code :

ScreenShot:

toolbar_swipetab toolbar_swipetab3 toolbar_swipetab2

Download SourceCode

 

 

 

  • Alisson

    Very good post! Thank you, it helped me a lot.

    • admin

      Thanks.

  • meivan

    Thanks, that was very useful.

    • admin

      Thanks.