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

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.

  • Do I really need to pass around Context instances deep into the application?
  • How to change the default language of ANDROID Emulator?
  • How to implement in-app-purchase using Cordova plugin?
  • Is it possible to lose a SQLite database connection?
  • Google Maps Fragment doesn't load
  • Android: Get the screen resolution / pixels as integer values
  • Related posts:

    How to use UsageStatsManager?
    Android:How to download the File from the server and save it in specific folder in sdcard
    Saving MapFragment (Maps v2) State in Android
    How to create scrollable page of carousels in Android?
    Google Analytics event tracking - max string length
    Calculating distance using Linear acceleration android
  • EditText setError message does not clear after input
  • Write to /res/drawable/ on the fly?
  • Why StringUtils Apache class is not recognized in Android?
  • How do I use InputFilter to limit characters in an EditText in Android?
  • How to create a video preview in android?
  • Creating login animation like facebook android
  • 2 Solutions collect form web for “How can I use an icon instead of a title in the Android Toolbar?”

    Use the following steps:

    1. Toolbar toolbar = (Toolbar) findViewById(R.id.tool1);
    2. setSupportActionBar(toolbar);
    3. Remove title by getSupportActionBar().setDisplayShowTitleEnabled(false);
    4. Add your logo in drawable folder in res/drawable.
    5. Add logo using toolbar.setLogo(R.drawable.ic_launcher);

    Here is the answer to a very similar question:
    Android Lollipop, add popup menu from title in toolbar

    It comes down to using the Toolbar as a ViewGroup (LinearLayout is a ViewGroup too, for instance). The layout designer doesn’t currently support that, but you can add a child node in the XML.

    Then you need to call this to remove the standard title text:
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.