I want to implement the same side menu on 4 activities. Googled. In different articles, everything is different and I'm generally confused. I understand you need one markup (basic), only the content changes. In the article one it was written that you need to create your own layout for each activity with its own content markup and override the setContentView(int) method. In general, I did not really understand, help finish the idea. Here is the markup

main.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:layout_height="?android:actionBarSize" android:background="#512da8"/> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <FrameLayout android:id="@+id/activity_content" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- меняется только это --> </FrameLayout> <include layout="@layout/navigation_view"/> </android.support.v4.widget.DrawerLayout> </LinearLayout> 

And here is the overridden method

 @Override public void setContentView(int main) { LinearLayout content = (LinearLayout) getLayoutInflater().inflate(R.layout.main, null); drawer = (DrawerLayout) content.findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, R.string.navigation_view_open, R.string.navigation_view_close); toggle.setDrawerIndicatorEnabled(true); drawer.addDrawerListener(toggle); toggle.syncState(); FrameLayout activityContainer = (FrameLayout)drawer.findViewById(R.id.activity_content); getLayoutInflater().inflate(main, activityContainer, true); super.setContentView(content); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); } 

Log now

 DrawerLayout must be measured with MeasureSpec.EXACTLY. 

Googled DrawerLayout in my DrawerLayout . What's wrong?

What about the fragments. I do not want to use them. Too difficult and inconvenient to be, the content will be linked to each other and the sidebar.

  • I don’t write for android, new case with XAML (and the approach to creating both in android and in UWP is almost the same), I would have done what you don’t want =) I would do 2 Grid.ColumnDefinition. In the null column implemented the menu, and in the right column implemented frames, having previously described a single style that would be connected to other frames. - Amateur

1 answer 1

In your case, the most convenient way is to use this MaterialDrawer library. And the standard implementation implies that you will change fragments on a single activation.

  • Your link does not work - elik
  • @ pavel163, and how to use it on several activities? - Flippy
  • @ Sergey Grushin You will need to do initialization on each activation. I would create some abstract basic activit with initialization of the panel, and inherit all the activations in which you need a sidebar from the base - pavel163
  • @elik works for me. - pavel163
  • @ pavel163, I already use the ViewFlipper to change screens. - Flippy