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

45,236

Solution 1

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>

Solution 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/

Solution 3

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

Share:
45,236

Related videos on Youtube

KarlKarlsom
Author by

KarlKarlsom

Updated on November 23, 2020

Comments

  • KarlKarlsom
    KarlKarlsom over 3 years

    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>
    
  • KarlKarlsom
    KarlKarlsom over 12 years
    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.
  • adneal
    adneal over 12 years
    @KarlKarlsom I updated my original post, sorry about that confusion.
  • KarlKarlsom
    KarlKarlsom over 12 years
    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.
  • alexismorin
    alexismorin almost 11 years
    To show the logo instead of an icon, use:<item name="android:displayOptions">useLogo</item>