【问题标题】:Is it possible to implement bottom tab bar functionality like iOS in android? [closed]是否可以在android中实现像iOS这样的底部标签栏功能? [关闭]
【发布时间】:2016-03-12 08:38:02
【问题描述】:

在 iOS 中,底部标签栏功能非常基础。但在 android 中,我无法实现此功能。 我的想法如下。 标签栏包含短信、通话、相机 - 3 个标签栏图标。 每当点击这个图标时,我想运行安装在我的安卓设备上的短信、电话和相机。 但这些应该与 iOS 选项卡视图相同。 (不应该是全屏) 我已经找到了很长时间的解决方案,但我找不到正确的方法。 请帮我 谢谢

【问题讨论】:

    标签: android android-layout android-tabhost


    【解决方案1】:

    把它放在 XML 中

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/home_background_color"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/white"
        app:tabPadding="10dp"
        android:minHeight="100dp"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/app_primary_color"
        app:tabMode="fixed"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
    

    这在代码中

     try
        {
            tabLayout.addTab(tabLayout.newTab());
            tabLayout.addTab(tabLayout.newTab());
            tabLayout.addTab(tabLayout.newTab());
            tabLayout.addTab(tabLayout.newTab());
            tabLayout.getTabAt(0).setIcon(R.drawable.tab_icon1);
            tabLayout.getTabAt(1).setIcon(R.drawable.tab_icon2);
            tabLayout.getTabAt(2).setIcon(R.drawable.tab_icon3);
            tabLayout.getTabAt(3).setIcon(R.drawable.tab_icon4);
        }
        catch (Exception e)
        {
            Log.e("TabLayout Creation Error",e.getMessage());
        }
    
    
    
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
    switch(tabLayout.getSelectedTabPosition())
        {
        case 0:
    
    break;
            case 1:
    //Do the stuff
    break;
            case 2:
    //Do the stuff
    break;
            case 3:
    //Do the stuff
    break;
            }
         }
    
            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
    
            }
    
            @Override
            public void onTabReselected(TabLayout.Tab tab) {
    
            }
        });
    

    【讨论】:

    • 是的,你是对的,但我认为这不是我们可以显示安装在 android 设备上的应用程序的方式。我正在尝试,但他们同时全屏显示,标签栏不显示。
    • 伙计,你需要将意图放在开关的每个案例中,通过特定意图启动你想要的相应应用程序,这是你问题的答案,而不是你需要澄清你的问题你想要
    • 感谢您的回复。但我已经尝试过了。那么,我可以问你一个问题吗?您可以在某些 LinearLayout 中运行已安装的应用程序吗?我期待着您的回复。谢谢你的好意。
    • 您的具体问题是什么?
    • 是否可以用标签栏显示短信、通话、相机?
    【解决方案2】:

    是的,底部的标签栏是可能的 试试这个

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    
    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <RelativeLayout
            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="fill_parent" />
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:divider="@drawable/bg_tab_seperator"
                android:dividerPadding="0dp" />
        </RelativeLayout>
    </TabHost>
    

    【讨论】:

    • 是的,你是对的,但我认为这不是我们可以显示安装在 android 设备上的应用程序的方式。我正在尝试,但他们同时全屏显示,标签栏不显示。
    【解决方案3】:

    我已经在我的一个应用程序中实现了你所说的......我很快就会发布 xm

        <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
    
                <android.support.v4.view.ViewPager    
                    android:id="@+id/viewpager"    
                    android:layout_width="match_parent"    
                    android:layout_height="match_parent"    
                    android:layout_alignParentTop="true"    
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    android:layout_above="@+id/app_bar"/>
    
                <android.support.design.widget.AppBarLayout    
                    android:id="@+id/app_bar"    
                    android:layout_width="match_parent"    
                    android:layout_height="wrap_content"    
                    android:layout_alignParentBottom="true"    
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    android:background="@color/background"
                    >
    
                    <com.****.****.ui.custom.IconTextTabLayout    
                        android:id="@+id/tabs"    
                        android:layout_width="match_parent"    
                        android:layout_height="@dimen/custom_tab_layout_height"
                        app:tabGravity="fill"
                        app:tabMode="fixed" />
                </android.support.design.widget.AppBarLayout>
    </RelativeLayout>
    

    我的&lt;com.****.****.ui.custom.IconTextTabLayout 只是一个扩展TabLayout 的类,您可以使用默认小部件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多