How to add title in Navigation drawer layout?
Solution 1
Put a TextView
above a ListView
, and wrap it inside a vertical LinearLayout
. Give to your ListView android:layout_weight="1"
and android:layout_height="0dip"
Solution 2
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
.
Related videos on Youtube
wawanopoulos
Updated on October 12, 2020Comments
-
wawanopoulos over 3 years
[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,
-
Enrique Diaz almost 11 yearsDo you have any idea about how to add several titles?
-
karlstackoverflow over 10 yearsDo you have a more complete code sample?
-
Georgi Angelov about 10 yearsGreat solution!!! Thank you.
-
siddharth almost 9 yearsi also want to add this title. can you describe how can i do this?
-
-
CommonsWare almost 11 yearsThat will work if the header is to be fixed at the top. The screenshot shows headers as part of the
ListView
itself (see "Title 2" row). Your solution may be what the OP is seeking, though. -
Blackbelt almost 11 yearsYes I misunderstood him. Only now I realized he wants
-
Jacob Phillips almost 11 years
-
Lorenzo Barbagli over 10 yearsooohhh..... never give 0dip tu height of a listview.. try it and see in DDMS how long does the method "onMeasure" takes to be executed..