简体   繁体   中英

I want to make navigation view on my tabs whereby u click the 3 bar it will so navigation view. How do i do that?

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer">

<android.support.design.widget.NavigationView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:menu="@menu/nav_menu"
    android:layout_gravity="start"
    android:id="@+id/navigation_view"
    ></android.support.design.widget.NavigationView>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">


    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#d3d3d3"
        app:tabSelectedTextColor="#000000"
        app:tabTextColor="#000000">


        <android.support.design.widget.TabItem
            android:id="@+id/tabItem"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="All Terminal" />


        <android.support.design.widget.TabItem
            android:id="@+id/tabItem1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Terminal 1" />

        <android.support.design.widget.TabItem
            android:id="@+id/tabItem2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Terminal 2" />

        <android.support.design.widget.TabItem
            android:id="@+id/tabItem3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Terminal 3" />


    </android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>

This is the coding i have for now on the main page, not tab 1 2 or 3. I want to make navigation appear when u click the 3 bar the side navigation tab will show. How do I change the XML file to do that? for now it shows different thing from what I want.

For this you need to implement logic in your java file:
Add following code in your activity or java file

final DrawerLayout drawerLayout=findViewById(R.id.drawerLayout);
TabLayout tabLayout = findViewById(R.id.tabs);

                final int[] counterTabLast = {0};
                tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
                    @Override
                    public void onTabSelected(TabLayout.Tab tab) {
                        if(tab.getPosition()==2){ //Position 2 means third tab
                            counterTabLast[0] = counterTabLast[0] +1;
                            if(counterTabLast[0] ==3){//
                                drawerLayout.openDrawer(Gravity.START); //Open Drawer
                                counterTabLast[0]=0;// Reset counter tab
                            }
                        }
                    }

                    @Override
                    public void onTabUnselected(TabLayout.Tab tab) {

                    }

                    @Override
                    public void onTabReselected(TabLayout.Tab tab) {

                    }
                });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM