Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change logo that appears in Android ActionBar programatically

Is there a way to change the logo that appears in the ActionBar inside an Activity instead of listing it in the Manifest?

The reason I ask is I have an app for phones where I build a similar type of bar across the top with the launcher icon in the left corner similar to the ActionBar using an ImageView.

I also allow the user to change that image to one on their phone or on the internet. I am currently making the app work for tablets and would like to just use the ActionBar instead but can't figure out how to change the image based on the user. There is no method in the ActionBar class and I could not find a way to modify the icon or logo from the resources.

Anyone know if this is possible or could suggest something I could try?

like image 476
Chris Avatar asked Nov 22 '11 21:11

Chris


People also ask

How to set icon in ActionBar in Android Studio?

To generate ActionBar icons, be sure to use the Asset Studio in Android Studio. To create a new Android icon set, right click on a res/drawable folder and invoke New -> Image Asset.

What is Android ActionBar?

Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button. In general an ActionBar consists of the following four components: App Icon: App branding logo or icon will be displayed here.


1 Answers

Prior to the introduction in API 14 of the setIcon and setLogo methods that Jake mentions, you appear to be able to change the ActionBar logo by grabbing the view of android.R.id.home and setting a new drawable.

ImageView logo = (ImageView) findViewById(android.R.id.home);
logo.setImageDrawable(drawable);
like image 119
bdls Avatar answered Sep 30 '22 05:09

bdls