0

I want to implement a tabs in tabs screen as below:

image

Can you give me an example of this kind of screen?

huu duy
  • 2,049
  • 21
  • 31

2 Answers2

0

There is a good Android Google webpage @ SlidingTabsBasic and supporting details @ ViewPager class. Few months ago, I had the same answer with more details, hopefully I will find it for you.

I just found a link on SO @ Android - Google Play like tabs. The Tianhai's answer uses the sample project I implemented. The sample project (PagerSlidingTabStrip) on Riccardo's answer may be good too. I can claim that SlidingTabsBasic is a basic tab like GUI project.

In the meantime, is this a good start for you?

Community
  • 1
  • 1
The Original Android
  • 6,147
  • 3
  • 26
  • 31
0

Try This:

MainActivity

public class MainActivity extends TabActivity {

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Resources ressources = getResources();
    TabHost tabHost = getTabHost();

    // Android tab
    Intent intentAndroid = new Intent().setClass(this, AndroidActivity.class);
    TabSpec tabSpecAndroid = tabHost
            .newTabSpec("Android")
            .setIndicator("", ressources.getDrawable(R.drawable.icon_android_config))
            .setContent(intentAndroid);

    // Apple tab
    Intent intentApple = new Intent().setClass(this, AppleActivity.class);
    TabSpec tabSpecApple = tabHost
            .newTabSpec("Apple")
            .setIndicator("", ressources.getDrawable(R.drawable.icon_apple_config))
            .setContent(intentApple);

    // Windows tab
    Intent intentWindows = new Intent().setClass(this, WindowsActivity.class);
    TabSpec tabSpecWindows = tabHost
            .newTabSpec("Windows")
            .setIndicator("", ressources.getDrawable(R.drawable.icon_windows_config))
            .setContent(intentWindows);

    // Blackberry tab
    Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);
    TabSpec tabSpecBerry = tabHost
            .newTabSpec("Berry")
            .setIndicator("", ressources.getDrawable(R.drawable.icon_blackberry_config))
            .setContent(intentBerry);

    // add all tabs
    tabHost.addTab(tabSpecAndroid);
    tabHost.addTab(tabSpecApple);
    tabHost.addTab(tabSpecWindows);
    tabHost.addTab(tabSpecBerry);

    //set Windows tab as default (zero based)
    tabHost.setCurrentTab(2);
}

}

activity_main

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />
</LinearLayout>

AndroidActivity

public class AndroidActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Resources ressources = getResources();
    TabHost tabHost = getTabHost();

    // Android tab
    Intent intentAndroid = new Intent().setClass(this, AppleActivity.class);
    TabHost.TabSpec tabSpecAndroid = tabHost
            .newTabSpec("Android")
            .setIndicator("", ressources.getDrawable(R.drawable.icon_android_config))
            .setContent(intentAndroid);

    // Apple tab
    Intent intentApple = new Intent().setClass(this, AppleActivity.class);
    TabHost.TabSpec tabSpecApple = tabHost
            .newTabSpec("Apple")
            .setIndicator("", ressources.getDrawable(R.drawable.icon_apple_config))
            .setContent(intentApple);

    // Windows tab
    Intent intentWindows = new Intent().setClass(this, WindowsActivity.class);
    TabHost.TabSpec tabSpecWindows = tabHost
            .newTabSpec("Windows")
            .setIndicator("", ressources.getDrawable(R.drawable.icon_windows_config))
            .setContent(intentWindows);

    // Blackberry tab
    Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);
    TabHost.TabSpec tabSpecBerry = tabHost
            .newTabSpec("Berry")
            .setIndicator("", ressources.getDrawable(R.drawable.icon_blackberry_config))
            .setContent(intentBerry);

    // add all tabs
    tabHost.addTab(tabSpecAndroid);
    tabHost.addTab(tabSpecApple);
    tabHost.addTab(tabSpecWindows);
    tabHost.addTab(tabSpecBerry);

    //set Windows tab as default (zero based)
    tabHost.setCurrentTab(0);

 }

AppleActivity

public class AppleActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView textview = new TextView(this);
    textview.setText("This is Apple tab");
    setContentView(textview);
}

BlackBerryActivity

public class BlackBerryActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView textview = new TextView(this);
    textview.setText("This is BlackBerry tab");
    setContentView(textview);
}

WindowActivity

public class WindowsActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView textview = new TextView(this);
    textview.setText("This is Windows mobile tab");
    setContentView(textview);
}
Chaudhary Amar
  • 836
  • 8
  • 20