【问题标题】:Custom Home Icon in Action Bar Sherlock操作栏中的自定义主页图标 Sherlock
【发布时间】:2011-12-18 17:20:24
【问题描述】:

我正在尝试使用ActionBarSherlock library 为主页图标设置自定义图标。我尝试在自定义主题中使用 abHomeLayout 属性设置自定义布局。但这对我不起作用。如何设置它的唯一方法是为我的自定义drawble设置abIcon属性,但我不能为此drawable设置一些水平填充。是否有任何示例或abHomeLayout 属性可能存在问题?

【问题讨论】:

    标签: android drawable android-actionbar actionbarsherlock


    【解决方案1】:

    这适用于我的情况,它将操作栏中的默认 ic_launcher 图标替换为我的自定义图标。

    在你的 onCreate 中这样做:

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

    或者在清单中你可以设置标志:

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

    【讨论】:

      【解决方案2】:

      这也很好用:

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

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

      【讨论】:

        【解决方案3】:

        我有类似的问题,设备 apiabHomeLayout 样式仅适用于 api>11

        我的解决方案是将 abs__action_bar_home.xml 布局从 ABS 复制到子项目并手动将填充添加到 abs__home 图像视图

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

        【讨论】:

        • 您是否还需要添加到您的样式等中以使其生效?我已将相同的文件复制到我的项目的 res/layout/ 中,但对填充的调整似乎不起作用..
        • 不好的答案,甚至没有说如何应用这个布局
        【解决方案4】:

        定义自己的样式,如下所示:

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

        我认为您可以在这里使用abHomeLayout。 像这样为您的活动设置此样式:

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

        在 MainActivity 中,您可以使用 getSupportActionBar()... 函数。

        【讨论】:

        • 谢谢。如上所述,我已经尝试过abHomeLayout。没有成功,所以我需要一个工作示例。
        • 这是一个如何使用 ABS 的示例,但根本没有回答问题
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多