Is it possible to implement bottom tab bar functionality like iOS in android? [closed]

久未见 提交于 2019-12-13 09:06:24

问题


In iOS , bottom tab bar functionality is very basic. But in android , I can't implement this functionality. My idea is as follows. Tab bar contains SMS, Call, Camera - 3 tab bar icons. Whenever taps this icons, I want to run SMS, Phone call and Camera installed on my android device. But these should be the same as iOS tab View. (shouldn't be full screen) I have found solution for a long time, but I can't find the correct way. Please help me Thanks


回答1:


put this in the 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" />

and this in the code

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

        }
    });



回答2:


Yes it is possible tab bar in bottom try this

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




回答3:


I have implemented what youre saying in one my apps..ill post the xm shortly

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

my <com.****.****.ui.custom.IconTextTabLayout is nothing but a class which extends TabLayout you can use the default widget.



来源:https://stackoverflow.com/questions/35955494/is-it-possible-to-implement-bottom-tab-bar-functionality-like-ios-in-android

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