Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add title in Navigation drawer layout?

Tags:

[UPDATE]

I solve the problem by adding addHeaderView :

protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);      mTitle = mDrawerTitle = getTitle();     mPlanetTitles = getResources().getStringArray(R.array.planets_array);     mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);     mDrawerList = (ListView) findViewById(R.id.left_drawer);      LayoutInflater inflater = getLayoutInflater();     ViewGroup mTop = (ViewGroup)inflater.inflate(R.layout.header_listview_menu, mDrawerList, false);     mDrawerList.addHeaderView(mTop, null, false); 

================================

My question is so simple !

I would like to how to add a title in a navigation drawer ?

I already created my navigation drawer with listview (icon+text) for each item.

Thanks a lot,

enter image description here

like image 983
wawanopoulos Avatar asked Jun 05 '13 14:06

wawanopoulos


People also ask

How do I customize my navigation drawer?

Android App Development for BeginnersStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.


1 Answers

You would do that the same way as you would add headings in any other ListView, by teaching your ListAdapter to return heading rows as well as detail rows. At the low level, this involves overriding methods like getViewTypeCount() and getItemViewType() in your ListAdapter, plus having getView() know the difference between the row types. Or, use an existing high-level implementation like https://github.com/emilsjolander/StickyListHeaders or http://code.google.com/p/android-amazing-listview/ or any of the others found when searching for android listview headers.

like image 161
CommonsWare Avatar answered Sep 28 '22 04:09

CommonsWare