N
N
Nick20152015-08-30 17:17:02
Android
Nick2015, 2015-08-30 17:17:02

Navigation View and Toolbar?

Here's the thing...
There is an activity that contains the following components

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start_page_activity);
        mToolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        mNavigationView = (NavigationView)findViewById(R.id.main_drawer);
        mNavigationView.setNavigationItemSelectedListener(this);

        mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_widget);
        drawerToggle
                = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
        mDrawerLayout.setDrawerListener(drawerToggle);
        drawerToggle.syncState();

    }

layout
<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:id="@+id/drawer_widget"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            android:minHeight="?attr/actionBarSize"/>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/main_drawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/navigation_menu"/>

</android.support.v4.widget.DrawerLayout>

It is necessary to make it so that when opening (going to) a new activity, the ToolBar and NavigationView are displayed. I tried to make an abstract class, but it is necessary to make it so that when opening different activities, the contents of the toolbar change.
Tell me in which direction they are moving, I saw that the ToolBar layout is connected to all activities, but then what about the NavigationView? in each activity you will need to implement a listener ....

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question