Custom image instead of logo in ActionBar/ActionBarSherlock

14,211

Solution 1

The ActionBar uses the android:logo attribute of your manifest, if one is provided. That lets you use separate drawable resources for the icon (Launcher) and the logo (ActionBar, among other things).


So you should add this tag into manifest like ..

<application
    android:logo="@drawable/custom_image"

Update :

You can use ActionBar.setLogo() for runtime. Two versions are there setLogo(int resId) and setLogo(Drawable logo).

Read Define custom Logo for ActionBar (different than Logo) in XML? which will help you to define some styles also.

Solution 2

The simplest technique is to use setIcon(R.drawable.icon_name) Similarly you can do with the Title and you can also set the date in the action bar subtitle.

ActionBar ab= getActionBar();
ab.setTitle("Aries");
ab.setSubtitle(dateFormat.format(date));
ab.setIcon(R.drawable.aries3d);
Share:
14,211
Carlos
Author by

Carlos

Updated on June 12, 2022

Comments

  • Carlos
    Carlos almost 2 years

    How can I change the default logo icon of an ActionBar to be a custom image? Similar as how it works on Whatsapp? Whatsapp custom image as logo

  • Carlos
    Carlos over 10 years
    Yes. I'm aware of that. The problem is that I want to set a custom image to that icon. In whatsapp that image is a friend's profile picture (it is specified at runtime).
  • chip
    chip over 10 years
    you can use ActionBar.setIcon(Drawable)
  • samirprogrammer
    samirprogrammer about 10 years
    @carlos .. did you find solution.. i have same requirment.. thanks in advance
  • Faizan Mubasher
    Faizan Mubasher about 9 years
    Its not working and I don't know why. I have tried everything
  • Pankaj Kumar
    Pankaj Kumar about 9 years
    @FaizanMubasher What is not working? Can you ask one separate question with your code please?
  • Faizan Mubasher
    Faizan Mubasher about 9 years
    Actually! I can't ask separate question as that gonna be definitely negative ;-) . I have tried all things that mentioned here and also tried other threads. I don't know where I am getting wrong.
  • Pankaj Kumar
    Pankaj Kumar about 9 years
    @FaizanMubasher Hey I am sorry :( without code I can not help you. Hope you understand