【问题标题】:Android having tabs at the bottom of screen?Android 在屏幕底部有标签?
【发布时间】:2025-12-24 14:50:10
【问题描述】:

我正在尝试将选项卡放在屏幕底部并让每个选项卡显示不同的活动。

但是根据我的阅读,您只能在手机 3.0+ 上使用它。

当我知道的大多数手机都在 2.3 左右时,这似乎有点荒谬。

有人有什么想法吗?

【问题讨论】:

标签: android android-layout android-widget android-tabhost


【解决方案1】:

这可以使用android常用选项卡来实现,只需在xml中添加一些额外的代码。我希望这段代码可以帮助你完成它......

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

样式在这里@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】:

    您可以通过片段和底部的一组按钮来最好地实现这一点。

    所以当一个按钮被点击时,无论用户点击什么,都会在主内容区域做一个片段转换。

    话虽如此,底部的标签在 Android 上是不好的形式。

    【讨论】:

    • 刚刚阅读了一些片段...它们可以在
    • 是的,使用支持库 jar,这支持回到 1.6。
    【解决方案3】:

    使用下面的 XML 代码作为底部标签栏。

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

    并使用下面的java代码。

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

    【讨论】:

      最近更新 更多