How to add profile information to the box for Android navigation?

Hi, I am working with Android. I added an Android navigation box, as in g mail for my application. Now I want to add a profile picture, as in the picture. I tried it on a list item. but I want more space just like in the image. How can i do this??? Please help me. I'm new to android enter image description here

here is my code for the list item

mTitle = mDrawerTitle = getTitle(); // load slide menu items navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items); // nav drawer icons from resources navMenuIcons = getResources() .obtainTypedArray(R.array.nav_drawer_icons); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.list_slidermenu); navDrawerItems = new ArrayList<NavDrawerItem>(); // adding nav drawer items to array // Home navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1))); navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1))); // Find People navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1))); // Photos navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1))); // Communities, Will add a counter here navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1), true, "22")); // Pages navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1))); // What hot, We will add a counter here navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1), true, "50+")); // Recycle the typed array navMenuIcons.recycle(); mDrawerList.setOnItemClickListener(new SlideMenuClickListener()); // setting the nav drawer list adapter adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems); mDrawerList.setAdapter(adapter); 
+8
android navigation
source share
5 answers

First, I would say that you need to rank your information in order of importance. The username is apparently the most important and therefore what they need to see in order to tell them

a) they are logged in and

b) with which account they are logged in.

for more information on this link https://ux.stackexchange.com/questions/44776/navigation-drawer-with-my-account-entry

-one
source share

I will also solve this problem. Just change some of the code in XML and Java.

Change the code by following the code ...... I think solve your problem

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" > <!-- Framelayout to display Fragments --> <FrameLayout android:id="@+id/frame_container" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- Listview to display slider menu --> <LinearLayout android:id="@+id/drawerll" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:orientation="vertical" > <LinearLayout android:id="@+id/drawer" android:layout_width="240dp" android:layout_height="wrap_content" android:layout_gravity="start" android:background="@color/list_item_title" android:gravity="center_vertical" android:orientation="horizontal" > <ImageView android:layout_width="80dp" android:layout_height="80dp" android:paddingLeft="20dp" android:src="@drawable/pic_pic" /> <LinearLayout android:id="@+id/drawer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:background="@color/list_item_title" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="Shohel Rana" android:textSize="14sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:gravity="center" android:text="test@gmail.com" android:textSize="14sp" /> </LinearLayout> </LinearLayout> <ListView android:id="@+id/list_slidermenu" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/list_item_title" android:choiceMode="singleChoice" android:dividerHeight="1dp" android:listSelector="@drawable/list_selector" /> </LinearLayout> </android.support.v4.widget.DrawerLayout> 

And Java code Just added below code:

final boolean drawerOpen = mDrawerLayout.isDrawerOpen (drawerll);

here drawerll stands for Total linear Layout. as well as mDrawerLayout.closeDrawer (drawerll);

and close Layer Layout ....

Here's the Total Java Code:

 package by.fitbody;`enter code here` import java.util.ArrayList; import android.app.ActionBar; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; import android.app.SearchManager; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.SearchView; import android.widget.Toast; import by.fitbody.adapter.NavDrawerListAdapter; import by.fitbody.model.NavDrawerItem; public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ListView mDrawerList; private ActionBarDrawerToggle mDrawerToggle; // nav drawer title private CharSequence mDrawerTitle; // used to store app title private CharSequence mTitle; // slide menu items private String[] navMenuTitles; // private TypedArray navMenuIcons; private ArrayList<NavDrawerItem> navDrawerItems; private NavDrawerListAdapter adapter; private Context con = null; LinearLayout drawerll; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); con = this; final ActionBar bar = getActionBar(); bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor( R.color.customRed))); bar.setIcon(R.drawable.articles_05); mTitle = mDrawerTitle = getTitle(); // load slide menu items navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items); // nav drawer icons from resources // navMenuIcons = getResources() // .obtainTypedArray(R.array.nav_drawer_icons); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.list_slidermenu); drawerll = (LinearLayout) findViewById(R.id.drawerll); makeSlideList(); // enabling action bar app icon and behaving it as toggle button getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.main_menu, // nav menu toggle icon R.string.app_name, // nav drawer open - description for // accessibility R.string.app_name // nav drawer close - description for // accessibility ) { @Override public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); // calling onPrepareOptionsMenu() to show action bar icons invalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); // calling onPrepareOptionsMenu() to hide action bar icons invalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { // on first time display view for first nav item displayView(0); } } /* * make slide list */`enter code here` private void makeSlideList() { // TODO Auto-generated method stub navDrawerItems = new ArrayList<NavDrawerItem>(); // adding nav drawer items to array // Home navDrawerItems.add(new NavDrawerItem(navMenuTitles[0])); // Find People navDrawerItems.add(new NavDrawerItem(navMenuTitles[1])); // Photos navDrawerItems.add(new NavDrawerItem(navMenuTitles[2])); // Communities, Will add a counter here navDrawerItems.add(new NavDrawerItem(navMenuTitles[3])); // Pages navDrawerItems.add(new NavDrawerItem(navMenuTitles[4])); // What hot, We will add a counter here navDrawerItems.add(new NavDrawerItem(navMenuTitles[5])); navDrawerItems.add(new NavDrawerItem(navMenuTitles[6])); navDrawerItems.add(new NavDrawerItem(navMenuTitles[7])); navDrawerItems.add(new NavDrawerItem(navMenuTitles[8])); // Recycle the typed array // navMenuIcons.recycle(); mDrawerList.setOnItemClickListener(new SlideMenuClickListener()); // setting the nav drawer list adapter adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems); mDrawerList.setAdapter(adapter); } /** * Slide menu item click listener * */ private class SlideMenuClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // display view for selected nav drawer item displayView(position); } } @Override public boolean onCreateOptionsMenu(Menu menu) { final MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.actionbarmenu, menu); // Associate searchable configuration with the SearchView final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchView searchView = (SearchView) menu.findItem( R.id.action_search).getActionView(); searchView.setSearchableInfo(searchManager .getSearchableInfo(getComponentName())); return super.onCreateOptionsMenu(menu); } /* * fo(non-Javadoc) * * @see android.app.Activity#onNewIntent(android.content.Intent) * * * for search bar */ @Override protected void onNewIntent(Intent intent) { setIntent(intent); handleIntent(intent); } /** * Handling intent data */ private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { final String query = intent.getStringExtra(SearchManager.QUERY); Log.e("Search text is ", query + ""); /** * Use this query to display search results like 1. Getting the data * from SQLite and showing in listview 2. Making webrequest and * displaying the data For now we just display the query only */ Toast.makeText(con, "Query is " + query, 1000).show(); } } @Override public boolean onOptionsItemSelected(MenuItem item) { // toggle nav drawer on selecting action bar app icon/title if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } // Handle action bar actions click switch (item.getItemId()) { case R.id.action_rate: Toast.makeText(con, "rate button is clicked", 1000).show(); return true; case R.id.action_best: Toast.makeText(con, "Best button is clicked", 1000).show(); return true; case R.id.action_liked: Toast.makeText(con, "liked button is clicked", 1000).show(); return true; default: return super.onOptionsItemSelected(item); } } /* * * Called when invalidateOptionsMenu() is triggered */ @Override public boolean onPrepareOptionsMenu(Menu menu) { // if nav drawer is opened, hide the action items /* * active those code if you want to hide options menu when drawer is * opened. */ final boolean drawerOpen = mDrawerLayout.isDrawerOpen(drawerll); menu.findItem(R.id.action_best).setVisible(!drawerOpen); menu.findItem(R.id.action_liked).setVisible(!drawerOpen); menu.findItem(R.id.action_rate).setVisible(!drawerOpen); return super.onPrepareOptionsMenu(menu); } /** * Diplaying fragment view for selected nav drawer list item * */ private void displayView(int position) { // update the main content by replacing fragments Fragment fragment = null; switch (position) { case 0: fragment = new ArticleFragment(position); break; case 1: fragment = new ArticleFragment(position); break; case 2: fragment = new ArticleFragment(position); break; case 3: fragment = new ArticleFragment(position); break; case 4: fragment = new ForumFragment(); break; case 5: final Intent i = new Intent(con, FitnessClubActivity.class); startActivity(i); break; case 6: fragment = new ArticleFragment(position); break; case 7: fragment = new ArticleFragment(position); break; case 8: fragment = new AboutUsFragment(); break; default: break; } if (fragment != null) { final FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.frame_container, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); setTitle(navMenuTitles[position]); mDrawerLayout.closeDrawer(drawerll); } else { // error in creating fragment Log.e("MainActivity", "Error in creating fragment"); } } @Override public void setTitle(CharSequence title) { mTitle = title; getActionBar().setTitle(mTitle); } /** * When using the ActionBarDrawerToggle, you must call it during * onPostCreate() and onConfigurationChanged()... */ @Override protected void onPostCreate(Bundle savedInstanceState) {enter code here` super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Pass any configuration change to the drawer toggls mDrawerToggle.onConfigurationChanged(newConfig); } } 

I think this will solve your problem:

I just changed the code for this site: http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

+9
source share

You can also use the custom view in NAvigatindrawer, not just listvew. Therefore, create a LinearLayout with your drawing and list, and you will get the result.

Take a look at this SO stream: Is it possible to use something other than a list like a sliding drawer in drawerlayout

Good luck;)

+1
source share

For your information only, you can use FB parsing, which gives you a very simple way to add these apis and easily get the data, they have simple documentation in stages, look

You can read about it here: https://www.parse.com/docs

0
source share

I solved it using

 mDrawerList.addHeaderView(); 

where you need to add a view object

0
source share

All Articles