我试图使用ActionBarSherlock库设置自定义主页图标。我尝试使用abHomeLayout
属性在我的自定义主题中设置自定义布局,但是对我没有作用。唯一的方法是通过为我的自定义drawable设置abIcon
属性来设置它,但我无法为此drawable设置一些水平填充。是否有任何示例或者关于abHomeLayout
属性的问题?
我试图使用ActionBarSherlock库设置自定义主页图标。我尝试使用abHomeLayout
属性在我的自定义主题中设置自定义布局,但是对我没有作用。唯一的方法是通过为我的自定义drawable设置abIcon
属性来设置它,但我无法为此drawable设置一些水平填充。是否有任何示例或者关于abHomeLayout
属性的问题?
这对我的情况有效,它用我的自定义图标替换了操作栏中的默认ic_launcher图标。
在你的onCreate方法中添加以下代码:
getSupportActionBar().setIcon(R.drawable.audio_shortcut);
或者在清单文件中设置logo:
<activity>
android:logo="@drawable/my_custom_logo"
...
</activity>
<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>
我曾经遇到过类似的问题,即在设备api<11上home图标的填充不正确(即不是完整的平台操作栏),而abHomeLayout
样式只适用于api>11。
我的解决方案是从ABS中复制abs__action_bar_home.xml
布局到子项目中,并手动添加填充到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" />
定义自己的样式,就像这样:
<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>