Custom Home Icon in Action Bar Sherlock

半城伤御伤魂 提交于 2019-12-02 23:33:34

This works for my situation, it replaces the default ic_launcher icon in the action bar with my custom one.

In your onCreate do this:

getSupportActionBar().setIcon(R.drawable.audio_shortcut);

Or in the manifest you can set the logo:

<activity>
    android:logo="@drawable/my_custom_logo"
    ...
</activity>
Brais Gabin

This works great too:

<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    <item name="icon">@drawable/my_custom_logo</item>
    <item name="android:icon">@drawable/my_custom_logo</item>
</style>

Reference: How to change the ActionBar “Home” Icon to be something other than the app icon?

I had similar issue with incorrect padding of the home icon on devices api<11 (i.e not the fully fledged platform action bar) and the abHomeLayout style only worked api>11

My solution was to copy the abs__action_bar_home.xml layout from ABS to child project and manually add padding to the abs__home imageview

<ImageView
    android:id="@+id/abs__home"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:paddingTop="@dimen/action_bar_home_icon_top_bottom_padding"
    android:paddingBottom="@dimen/action_bar_home_icon_top_bottom_padding"
    android:paddingLeft="@dimen/action_bar_home_icon_left_right_padding"
    android:paddingRight="@dimen/action_bar_home_icon_left_right_padding"
    android:scaleType="centerInside" />
andep

Define an own style, like this:

<resources>
  <style name="Theme.OwnTheme" parent="@style/Theme.Sherlock">
    <item name="abBackground">#476dd5</item>
    <item name="abHeight">30dip</item>
  </style>
</resources>

I think here your can use abHomeLayout. Set this style for your activity like this:

<activity 
 android:name=".MainActivity" 
 android:theme="@style/Theme.OwnTheme">
   <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

In MainActivity you can use getSupportActionBar()... functions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!