[英]Hide the icon in the ActionBar in Android
I am trying to hide the application logo from the ActionBar. 我正在尝试从ActionBar隐藏应用程序徽标。 In order to do that I am using the setDisplayHomeAsUpEnabled(boolean)
method: 为了做到这一点,我正在使用setDisplayHomeAsUpEnabled(boolean)
方法:
this.getActionBar().setDisplayHomeAsUpEnabled(true);
This works almost as intented, except for two things: 除以下两点外,这几乎可以达到预期目的:
How can I fix this? 我怎样才能解决这个问题?
试试: getActionBar().setDisplayUseLogoEnabled(false);
The icon is still visible when the application starts (and then disappear) 应用程序启动时该图标仍然可见(然后消失)
To avoid this you need to undisplay your logo from your style.xml
as follows: 为避免这种情况,您需要按以下方式从style.xml
取消显示徽标:
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/mActionBar</item>
<item name="actionBarStyle">@style/mActionBar</item>
</style>
<style name="mActionBar" parent="@style/Widget.Holo.Light.ActionBar">
<item name="android:icon">@android:color/transparent</item>
<item name="icon">@android:color/transparent</item>
</style>
Because your app starts with loading your Theme
and then after displays your UI by your Activity
. 因为您的应用程序首先加载Theme
,然后再通过Activity
显示UI。 Also, this will be a resource way, because your activities will not reload the UI like the home icon, etc. since they are first initialized thanks to the theme. 另外,这将是一种资源途径,因为您的活动不会像主图标那样重新加载UI,因为由于主题的缘故它们首次被初始化。
The navigation drawer icon is not visible on some devices 在某些设备上看不到导航抽屉图标
Make sure you have this following snippnet code: 确保您具有以下片段代码:
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getActionBar().setTitle(mTitle);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getActionBar().setTitle(mDrawerTitle);
}
};
//...
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
And check your icon, or (re)download it . 并检查您的图标,或(重新)下载它 。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.