Android having tabs at the bottom of screen?

有些话、适合烂在心里 提交于 2019-12-25 05:25:13

问题


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?


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

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



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




回答3:


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);
    }
}


来源:https://stackoverflow.com/questions/11838671/android-having-tabs-at-the-bottom-of-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!