Custom image instead of logo in ActionBar/ActionBarSherlock
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);
Carlos
Updated on June 12, 2022Comments
-
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?
-
Carlos over 10 yearsYes. 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 over 10 yearsyou can use
ActionBar.setIcon(Drawable)
-
samirprogrammer about 10 years@carlos .. did you find solution.. i have same requirment.. thanks in advance
-
Faizan Mubasher about 9 yearsIts not working and I don't know why. I have tried everything
-
Pankaj Kumar about 9 years@FaizanMubasher What is not working? Can you ask one separate question with your code please?
-
Faizan Mubasher about 9 yearsActually! 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 about 9 years@FaizanMubasher Hey I am sorry :( without code I can not help you. Hope you understand