Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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

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

><RelativeLayoutandroid:id="@+id/LinearLayout01"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_above="@android:id/tabs"></FrameLayout><TabWidgetandroid: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

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

Solution 2:

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.

Solution 3:

Use below XML code for bottom tab bar.

<?xml version="1.0" encoding="utf-8"?><TabHostxmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/tabhost"android:layout_width="fill_parent"android:layout_height="fill_parent" ><RelativeLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"android:padding="3dp" ><FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_above="@android:id/tabs"android:layout_weight="1" /><TabWidgetandroid: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.

publicclassMainActivityextendsTabActivity {
    /** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

                setContentView(R.layout.tab_screen);
        TabHosttabHost= getTabHost();

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

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

        tabHost.setCurrentTab(0);
    }
}

Post a Comment for "Android Having Tabs At The Bottom Of Screen?"