Use tabs and navigation views on Android

Asked 2 years ago, Updated 2 years ago, 82 views

I'm a beginner in developing Android apps.

I was able to implement the tab, but when I try to install the navigation view next time, the layout is broken and I can't use it well.
Isn't there two elements in MainActivity?
It may be a curious question, but please tell me a good way.
Thank you for your cooperation.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android: orientation="vertical"
tools:context=".MainActivity"
android:weightSum="1">

<include
    android: id="@+id/tool_bar"
    layout="@layout/tool_bar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    />

<samples.exoguru.materialtabs.SlidingTabLayout
    android: id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="2dp"
    android:background="@color/ColorPrimary"/>

<android.support.v4.view.ViewPager
            android: id="@+id/pager"
            android:layout_height="match_parent"
            android:layout_width="match_parent">/android.support.v4.view.ViewPager>

android

2022-09-30 21:10

1 Answers

Use DrawerLayout.

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android: orientation="vertical"
        android:weightSum="1">
        <include
            android: id="@+id/tool_bar"
            layout="@layout/tool_bar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"/>
        <samples.exoguru.materialtabs.SlidingTabLayout
            android: id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="2dp"
            android:background="@color/ColorPrimary"/>
        <android.support.v4.view.ViewPager
            android: id="@+id/pager"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/> 
    </LinearLayout>
    <!--Drawer part is here -->
    <android.support.design.widget.NavigationView
        android: id="@+id/left_drawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:itemIconTint="@color/drawer_item"
        app:itemTextColor="@color/drawer_item"
        app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>


2022-09-30 21:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.