Reputation: 5093
I'm trying to show a logo in my action bar that is different from my app icon in an app that needs to be compatible with 2.3 (Gingerbread). Right now I have,
android:icon="@drawable/icon"
android:logo="@drawable/logo"
in my manifest file which correctly shows on 4.0 and above devices. However, all of the action bars on 2.3 devices show the icon instead of the logo. The following code in onCreate in an activity works on 2.3 devices:
getSupportActionBar().setLogo(getResources().getDrawable(R.drawable.logo));
But, I'd like to avoid having to set this separately in each of my activities. Is there a way to set this in xml, in the manifest or theme perhaps? I've also tried
<item name="android:icon">@drawable/logo_listy</item>
in my theme actionBarStyle.
Upvotes: 2
Views: 377
Reputation: 2647
I'm using Google's ActionBarCompat for this; if you're using ActionBarSherlock the same thing might work, but I haven't tried it.
You can set a logo in the style you have applied to the action bar in your app's theme. For example:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle" tools:targetApi="11">@style/AppTheme.ActionBar</item>
<item name="actionBarStyle">@style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- this can be set in the manifest or here, and will set the logo for -->
<!-- devices with API level >= 11 -->
<item name="android:logo" tools:targetApi="11">@drawable/logo</item>
<!-- this will set the logo for devices with API level < 11 -->
<item name="logo">@drawable/logo</item>
</style>
Upvotes: 1
Reputation: 413
You can specify android:icon for each activity in the AndroidManifest.xml.
Upvotes: 1