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.