How can I use an icon instead of a title in the Android Toolbar?
13,753
Use the following steps in your activity:
-
Declare the Toolbar object:
Toolbar toolbar = (Toolbar) findViewById(R.id.tool1);
-
Set the support actionbar:
setSupportActionBar(toolbar);
-
Remove title:
getSupportActionBar().setDisplayShowTitleEnabled(false);
-
Add your logo in drawable folder in:
res/drawable.
-
Add logo using this code:
toolbar.setLogo(R.drawable.ic_launcher);
Related videos on Youtube
Author by
murrayc
Managing director of Openismus GmbH. Maintainer of gtkmm.
Updated on July 08, 2022Comments
-
murrayc almost 2 years
I'm using the Toolbar (instead of ActionBar) via AppCompat. I'd like to replace the Toolbar's title (the app/actity name) with an icon, but I don't see how.
My icon is just text using a non-standard font, so I guess it might be allowed in Material Design.
-
murrayc over 9 yearsActually, kunal.c's answer is much better.
-
fnc12 about 7 yearshow to set logo dimensions/margin?
-
Tushar Gogna about 7 years@fnc12 how about "?attr/actionBarSize" ?
-
Nusret Özateş over 4 yearsBut what if I want to add another logo? For example, actual logo on the left and an image(image button actually) on the center.