You need to create a Base activity that does all the usual things of Drawer navigation . I will call this base of Activity as DrawerActivity , and all other Activity should expand this DrawerActivity . Thus, all Activity will have one instance of Drawer Layout .
Create a shared layout using DrawerLayout and put FrameLayout and ListView as a child
<android.support.v4.widget.DrawerLayout> <FrameLayout android:id="@+id/activity_frame"/> <ListView android:id="@+id/left_drawer"/> </android.support.v4.widget.DrawerLayout>
Now set this layout to onCreate() on DrawerActivity
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer_layout);
}
Add Click Viewer
private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { switch (position) { case 0: { Intent intent = new Intent(DrawerActivity.this, YourActivity.class); startActivity(intent); break; } default: break; } mDrawerLayout.closeDrawer(mLeftDrawerList); } }
Finally, all other actions will expand this DrawerActivity
public class MainActivity extends DrawerActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
Here you can see the full source https://gist.github.com/libinbensin/613dea436302d3015563
Libin
source share