Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use an icon instead of a title in the Android Toolbar?

Tags:

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.

like image 855
murrayc Avatar asked Nov 06 '14 16:11

murrayc


1 Answers

Use the following steps in your activity:

  1. Declare the Toolbar object:

    Toolbar toolbar = (Toolbar) findViewById(R.id.tool1); 
  2. Set the support actionbar:

    setSupportActionBar(toolbar);    
  3. Remove title:

    getSupportActionBar().setDisplayShowTitleEnabled(false); 
  4. Add your logo in drawable folder in:

    res/drawable. 
  5. Add logo using this code:

    toolbar.setLogo(R.drawable.ic_launcher); 
like image 53
kunal.c Avatar answered Oct 18 '22 03:10

kunal.c