droider
droider

Reputation: 302

Android having tabs at the bottom of screen?

I am trying to place tabs on the bottom of the screen and have each tab display a different activity.

However from what I have read you can only use this on phones 3.0+.

When most phones I know are around 2.3 this seems a little ridiculous.

Anyone have any ideas?

Upvotes: 0

Views: 382

Answers (3)

Dipak Keshariya
Dipak Keshariya

Reputation: 22291

Use below XML code for bottom tab bar.

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="3dp" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@android:id/tabs"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" />
    </RelativeLayout>

</TabHost>

and Use below java code.

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

                setContentView(R.layout.tab_screen);
        TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Home", getResources().getDrawable(R.drawable.home)).setContent(new Intent(this, HomeActivity.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Second", getResources().getDrawable(R.drawable.invoice)).setContent(new Intent(this, SecondActivity.class)));

        tabHost.setCurrentTab(0);
    }
}

Upvotes: 0

Sreedev
Sreedev

Reputation: 6653

This can be implemented using the android usual tab,just you have to do is add some extra codes in the xml.I hope this piece of code will help you for getting it done...

<TabHost 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:background="@android:color/background_dark"

>

    <RelativeLayout
        android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="match_parent" 
            android:layout_above="@android:id/tabs">
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            style="@style/customtab"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"

           >
        </TabWidget>
    </RelativeLayout>

</TabHost>

The style is here @style/customtab

   <style name="customtab" parent="@android:style/Widget.TabWidget">
            <item name="android:tabStripEnabled">false</item>
            <item name="android:tabStripLeft">@null</item>
            <item name="android:tabStripRight">@null</item>
        </style>

Upvotes: 1

Pork &#39;n&#39; Bunny
Pork &#39;n&#39; Bunny

Reputation: 6731

You can best achieve this with fragments and a set of buttons at the bottom.

So when a button is click, do a fragment transition on the main content area for whatever the user has clicked.

That being said, tabs at the bottom are bad form on Android.

Upvotes: 0

Related Questions