Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 829
KarlKarlsom Avatar asked Jan 04 '12 14:01

KarlKarlsom


3 Answers

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>
like image 183
garibay Avatar answered Nov 17 '22 03:11

garibay


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/

like image 30
adneal Avatar answered Nov 17 '22 03:11

adneal


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

like image 1
scottyab Avatar answered Nov 17 '22 03:11

scottyab