You can download it from here
When you put image in your navigation drawer you have to declare a layout, in this case relativeLayout.
In layout xml you declare a layout, now you put image inside layout, then you put listView.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | android:id = "@+id/drawer_layout" android:layout_width = "match_parent" android:layout_height = "match_parent" > <!-- main content --> < FrameLayout android:id = "@+id/content_frame" android:layout_width = "match_parent" android:layout_height = "match_parent" > </ FrameLayout > <!-- Menu --> < RelativeLayout android:id = "@+id/left_drawer" android:layout_width = "240dp" android:layout_height = "match_parent" android:layout_gravity = "start" android:background = "@drawable/degradee" android:orientation = "vertical" > < ImageView android:id = "@+id/image_view" android:layout_width = "match_parent" android:layout_height = "200dp" android:background = "@drawable/theworldisyours" /> < ListView android:id = "@+id/list_view_drawer" android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:layout_below = "@id/image_view" android:choiceMode = "singleChoice" /> </ RelativeLayout > </ android.support.v4.widget.DrawerLayout > |
In your class you declare
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | package com.thedeveloperworldisyours.navigationdrawer; import android.content.res.Configuration; import android.os.Bundle; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.Toast; import com.thedeveloperworldisyours.navigationdrawer.fragment.FirstFragment; import com.thedeveloperworldisyours.navigationdrawer.fragment.SecondFragment; import com.thedeveloperworldisyours.navigationdrawer.fragment.ThirdFragment; public class MainActivity extends ActionBarActivity { private String[] mOptionMenu; private DrawerLayout mDrawerLayout; private RelativeLayout mDrawerRelativeLayout; private ListView mDrawerList; private ActionBarDrawerToggle mDrawerToggle; private CharSequence mTitleSection; private CharSequence mTitleApp; private Fragment mFragment = null ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); mOptionMenu = new String[] { getString(R.string.first_fragment), getString(R.string.second_fragment), getString(R.string.third_fragment) }; mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerRelativeLayout = (RelativeLayout) findViewById(R.id.left_drawer); mDrawerList = (ListView) findViewById(R.id.list_view_drawer); mDrawerList.setAdapter( new ArrayAdapter<String>(getSupportActionBar() .getThemedContext(), android.R.layout.simple_list_item_1, mOptionMenu)); initContentWithFirstFragment(); mDrawerList.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0 : mFragment = new FirstFragment(); break ; case 1 : mFragment = new SecondFragment(); break ; case 2 : mFragment = new ThirdFragment(); break ; } FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.content_frame, mFragment).commit(); mDrawerList.setItemChecked(position, true ); mTitleSection = mOptionMenu[position]; getSupportActionBar().setTitle(mTitleSection); mDrawerLayout.closeDrawer(mDrawerRelativeLayout); } }); mDrawerList.setItemChecked( 0 , true ); mTitleSection = getString(R.string.first_fragment); mTitleApp = getTitle(); mDrawerToggle = new ActionBarDrawerToggle( this , mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(mTitleSection); ActivityCompat.invalidateOptionsMenu(MainActivity. this ); } public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(R.string.app_name); ActivityCompat.invalidateOptionsMenu(MainActivity. this ); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled( true ); getSupportActionBar().setHomeButtonEnabled( true ); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true ; } @Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true ; } switch (item.getItemId()) { case R.id.action_settings: Toast.makeText( this , R.string.action_settings, Toast.LENGTH_SHORT) .show(); ; break ; default : return super .onOptionsItemSelected(item); } return true ; } @Override protected void onPostCreate(Bundle savedInstanceState) { super .onPostCreate(savedInstanceState); mDrawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super .onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); } public void initContentWithFirstFragment(){ mTitleSection =getString(R.string.first_fragment); getSupportActionBar().setTitle(mTitleSection); mFragment = new FirstFragment(); FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.content_frame, mFragment).commit(); } } |
You can download it from here