Define custom Logo for ActionBar (different than Logo) in XML?
Asked Answered
P

4

23

I want to make a Actionbar_style.xml for my app and I would like to use a logo, different than my app logo / icon.

How to change it programmatcially is clear: Change logo that appears in Android ActionBar programatically But like this I would need to code this into each activity.

Is there a xml tag to define a custom Actionbarlogo in xml already?

my Customstyles.xml

<style name="CustomActionBar0" parent="android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@drawable/action_bg0</item>
</style>

android styles.xml seems not to have it...

<style name="Widget.ActionBar">
    <item name="android:background">@android:drawable/action_bar_background</item>
    <item name="android:displayOptions">useLogo|showHome|showTitle</item>
    <item name="android:divider">@android:drawable/action_bar_divider</item>
    <item name="android:height">?android:attr/actionBarSize</item>
    <item name="android:paddingLeft">0dip</item>
    <item name="android:paddingTop">0dip</item>
    <item name="android:paddingRight">0dip</item>
    <item name="android:paddingBottom">0dip</item>
    <item name="android:titleTextStyle">@android:style/TextAppearance.Widget.ActionBar.Title</item>
    <item name="android:subtitleTextStyle">@android:style/TextAppearance.Widget.ActionBar.Subtitle</item>
    <item name="android:progressBarStyle">@android:style/Widget.ProgressBar.Horizontal</item>
    <item name="android:indeterminateProgressStyle">@android:style/Widget.ProgressBar.Small</item>
    <item name="android:homeLayout">@android:layout/action_bar_home</item>
</style>
Potto answered 4/1, 2012 at 14:21 Comment(0)
C
36

Just set a value for the android:icon attribute

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/AppTheme.ActionBarStyle</item>
</style>

<style name="AppTheme.ActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@drawable/actionbar_background</item>
        <item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
        <item name="android:icon">@drawable/ic_home</item>
        <item name="android:indeterminateProgressStyle">@style/IndeterminateProgress</item>
</style>
Chenee answered 1/8, 2012 at 15:36 Comment(0)
A
2

You don't style the logo in the your style XML, you simply use android:logo in your Manifest, then use setDisplayUseLogoEnabled() to set it in the ActionBar. Here's a project, from Google, that shows you how to switch between the two. http://code.google.com/p/styled-action-bar/

Arbitrage answered 4/1, 2012 at 15:44 Comment(4)
No, the style of the action bar is applied, the background of the action bar is beeing changed. What I want is to change the home logo by XML declaration. Programatically I can do that with Actionbar.setLogo(). But I cant figure out how to do that by XML.Potto
@Potto I updated my original post, sorry about that confusion.Arbitrage
But the android:logo is used in other potions too (in 4.0 for example a task icon). But In the action bar I want to have a graphic that is not suitable as logo.Potto
To show the logo instead of an icon, use:<item name="android:displayOptions">useLogo</item>Biretta
G
1

Sounds like you need to use a custom layout for the action bar, that way you can define a whatever you want for logo image.

Action bar / ActionbarSherlock style

    <style name="ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
  <item name="displayOptions">showCustom</item>
  <item name="android:displayOptions">showCustom</item>

   <item name="customNavigationLayout">@layout/action_bar_home_icon_default</item>
   <item name="android:customNavigationLayout">@layout/action_bar_home_icon_default</item>
  </style>

@layout/action_bar_home_icon_default is your custom layout, with your custom logo

Genagenappe answered 30/7, 2012 at 16:26 Comment(0)
P
-1

Yes. You may set different logo for different activities. Here is the sample code in manifest file.

<activity
   android:name="MyActivity"
   ***android:icon="@drawable/logo"***            
   android:label="@string/app_name"
   android:configChanges="orientation"           
   android:screenOrientation="portrait" />

Hope this help. Cheers!

Phina answered 23/11, 2012 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.