The design of the material navigation box does not extend

I followed the instructions of https://stackoverflow.com/a/4129609/ and I was able to get the ActionBarDrawerToggle and its animation. However, the navigation box does not extend. Why is this?

activity_main.xml:

 <LinearLayout 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/container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" tools:ignore="MergeRootFrame" android:fitsSystemWindows="true" > <include layout="@layout/toolbar" /> <it.neokree.materialtabs.MaterialTabHost android:id="@+id/materialTabHost" android:layout_width="match_parent" android:layout_height="48dp" app:textColor="#FFFFFF" app:primaryColor="#33B5E5" app:accentColor="#FFFFFF" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- Main layout --> <FrameLayout android:id="@+id/main_fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- Nav drawer --> <fragment android:id="@+id/nav_drawer" android:name="com.wsandhu.conjugation.DrawerFragment" android:layout_width="@dimen/drawer_width" android:layout_height="match_parent" android:layout_gravity="left|start" /> </android.support.v4.widget.DrawerLayout> </LinearLayout> 

Here is the code in the onCreate() method in MainActivity.java :

 ActionBarDrawerToggle mDrawerToggle; DrawerLayout mDrawerLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name); mDrawerLayout.setDrawerListener(mDrawerToggle); ... if (savedInstanceState == null) { new Handler().post(new Runnable() { @Override public void run() { getSupportFragmentManager().beginTransaction() .add(R.id.container, new MainFragment()) .commit(); } }); } ... } 

I have a DrawerFragment class and its XML file, but, as I said, nothing comes out when I click ActionBarDrawerToggle in my application. The switch animates perfectly.

Five methods that need to be overridden, as indicated in another post, are in my MainActivity after the onCreate() method. I really don't know what else to add, I can't figure it out.

Thanks in advance.

+1
android material-design navigation-drawer
Jan 04 '15 at 2:07
source share
1 answer

I did not understand DrawerLayout , in part due to jpardogo's answer.

I needed to set the correct main content in my activity XML file, so I made android.support.v4.widget.DrawerLayout root element of the file and placed my LinearLayout activity above the fragment navigation box element. Here is the correct working code:

 <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_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- Main layout --> <LinearLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" tools:ignore="MergeRootFrame" android:fitsSystemWindows="true" > <include layout="@layout/toolbar" /> <it.neokree.materialtabs.MaterialTabHost android:id="@+id/materialTabHost" android:layout_width="match_parent" android:layout_height="48dp" app:textColor="#FFFFFF" app:primaryColor="#33B5E5" app:accentColor="#FFFFFF" /> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> <!-- Nav drawer --> <fragment android:id="@+id/nav_drawer" android:name="com.wsandhu.conjugation.DrawerFragment" android:layout_width="@dimen/drawer_width" android:layout_height="match_parent" android:layout_gravity="left|start" /> </android.support.v4.widget.DrawerLayout> 

This will help compare this with the XML file in the original message. Hope this helps.

0
Jan 06 '15 at 7:40
source share



All Articles