Custom Home Icon in Action Bar Sherlock

前端 未结 4 535
名媛妹妹
名媛妹妹 2021-02-03 21:34

I am trying to set custom icon for home icon using ActionBarSherlock library. I have tried to set custom layout using abHomeLayout attribute in my custom theme. But

相关标签:
4条回答
  • 2021-02-03 21:53

    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" />
    
    0 讨论(0)
  • 2021-02-03 21:54

    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?

    0 讨论(0)
  • 2021-02-03 21:58

    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.

    0 讨论(0)
  • 2021-02-03 22:01

    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>
    
    0 讨论(0)
提交回复
热议问题