ActionBar上的自定义主页按钮 [英] Custom home button on ActionBar
问题描述
我正在使用ActionBar Sherlock库。因此,要更改默认的主页按钮。我是这样做的:
I am using ActionBar Sherlock library. So, to change the default home button. I did this:
<style name="Theme.mTheme" parent="android:Theme.Sherlock.Light.DarkActionBar">
<item name="android:homeAsUpIndicator">@drawable/custom_home</item>
</style>
无效的
,我也添加了此内容:
So, i added this too:
<item name="homeAsUpIndicator">@drawable/custom_home</item>
现在可以正常工作了。我在每个ActionBar上都有此自定义主页图标/按钮。但是在我的活动之一中,我的代码是:
now its working. I am having this custom home icon/button on every ActionBar. But in 1 of my Activities i have this in code:
actionBar.setIcon(R.drawable.options_holo_dark);
当我处于该活动中时,可以看到我以编程方式设置的图标,即.. options_holo_dark 。我在主题中设置的1,即 custom_home 不可见。但是图标已移到右侧,好像它在主题中设置的图标左边的空格(虽然不可见)。
When i am in that Activity, I can see the icon which i set programatically ie.., options_holo_dark. The 1 which i set in Theme ie.., custom_home is not visible. But the Icon has moved to the Right as if its giving space on the left to the icon i set in theme(though not visible).
这就是我得到的现在:
那么,如何避免显示主页图标左侧的空白?
So, how can i avoid that empty space on the left side of the Home Icon?
谢谢
推荐答案
主题项目 android:homeAsUpIndicator
(和 homeAsUpIndicator
(用于 ActionBarSherlock
)将可绘制的向上图标设置为可绘制-这是指向左侧的小箭头,当您调用<$时,该小箭头显示在应用程序图标旁边c $ c> setDisplayHomeAsUpEnabled(true)。
Theme item android:homeAsUpIndicator
(and homeAsUpIndicator
for ActionBarSherlock
) sets drawable for the up icon - that's the little arrow pointing to left that is displayed next to the app icon when you have called setDisplayHomeAsUpEnabled(true)
on the action bar.
up drawable的大小定义了应用程序图标(徽标)的左边距。默认情况下,其尺寸为16dp x 16dp。如果您在此处放置更宽的可绘制对象,即使此时没有显示向上图标,屏幕边缘和应用程序图标之间的间隙也会更宽。
The size of the up drawable defines the left margin for the app icon (logo). By default its dimensions are 16dp x 16dp. If you put there wider drawable the gap between edge of the screen and the app icon would be wider even though the up icon is not displayed at the moment.
如果需要更改应用程序图标(徽标)。使用 ActionBar $ c $的
setLogo(int)
或 setLogo(Drawable)
方法c>。不要忘记也调用 setDisplayUseLogoEnabled(true)
-此方法在显示应用程序图标和自定义徽标之间切换。您也可以在清单的清单中的 android:logo
和的
标签,并在操作栏中设置要使用徽标而不是应用程序图标的主题。< application>
属性中定义徽标>< activity>
If you want to change the app icon (logo). Use setLogo(int)
or setLogo(Drawable)
method of ActionBar
. Don't forget to call setDisplayUseLogoEnabled(true)
too - this method toggles between displaying app icon and custom logo. Also you can define the logo in manifest in attribute android:logo
of <application>
and <activity>
tags and set in theme that you want to use logo instead of app icon in the action bar.
这篇关于ActionBar上的自定义主页按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!