[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,
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With