2

I am trying to show the tabs at the bottom of the screen. I have the following code and it is showing tabs at the bottom in design preview and emulator but when I test the code on real device tabs are showing at the top. Can't understand why. I already tried the answers on stackoverflow and other sites like: but no use

Android: Tabs at the BOTTOM

How to show tabs At Bottom rather then at top?

Android having tabs at the bottom of screen?

This is the code:

<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">

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:layout_weight="1"/>

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:layout_marginBottom="-4dp"
        android:gravity="center_vertical|center_horizontal|bottom" />

</LinearLayout>

And this is my activity code:

public class AndroidTabLayoutActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();

        // Tab for Photos
        TabHost.TabSpec photospec = tabHost.newTabSpec("");
        // setting Title and Icon for the Tab
        photospec.setIndicator("", getResources().getDrawable(R.drawable.icon_photos_tab));
        Intent photosIntent = new Intent(this, PhotosActivity.class);
        photospec.setContent(photosIntent);

        // Tab for Songs
        TabHost.TabSpec songspec = tabHost.newTabSpec("");
        songspec.setIndicator("", getResources().getDrawable(R.drawable.icon_songs_tab));
        Intent songsIntent = new Intent(this, SongsActivity.class);
        songspec.setContent(songsIntent);

        //Tab for Lists
        TabHost.TabSpec listspec = tabHost.newTabSpec("");
        listspec.setIndicator("", getResources().getDrawable(R.drawable.icon_lists_tab));
        Intent listIntent = new Intent(this, ListsActivity.class);
        listspec.setContent(listIntent);

        // Tab for Videos
        TabHost.TabSpec videospec = tabHost.newTabSpec("");
        videospec.setIndicator("", getResources().getDrawable(R.drawable.icon_videos_tab));
        Intent videosIntent = new Intent(this, VideosActivity.class);
        videospec.setContent(videosIntent);

        // Adding all TabSpec to TabHost
        tabHost.addTab(photospec); // Adding photos tab
        tabHost.addTab(songspec); // Adding songs tab
        tabHost.addTab(listspec); //Adding lists tab
        tabHost.addTab(videospec); // Adding videos tab

        // Set drawable images to tab
        tabHost.getTabWidget().getChildAt(1).setBackgroundColor(Color.parseColor("#1D2023"));
        tabHost.getTabWidget().getChildAt(2).setBackgroundColor(Color.parseColor("#1D2023"));
        tabHost.getTabWidget().getChildAt(3).setBackgroundColor(Color.parseColor("#1D2023"));

        // Set Tab1 as Default tab and change image
        tabHost.getTabWidget().setCurrentTab(0);
        tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#1D2023"));
    }
     }

any help will be greatly appreciated ...

Community
  • 1
  • 1
Umair
  • 6,366
  • 15
  • 42
  • 50
  • Check the third answer here from Harry: http://stackoverflow.com/questions/19098366/how-can-i-put-fragmenttabhost-tabs-at-the-bottom-of-the-screen – airowe Oct 06 '15 at 14:19

0 Answers0