Remove application icon and title from Honeycomb action bar

隐身守侯 提交于 2019-12-17 04:45:30

问题


How can I remove the application icon & title which comes by default in an action bar?

There is a similar question here: Can i hide the App Icon from the Action Bar in Honeycomb?, but it doesn't talk about how to do it?


回答1:


Call setDisplayShowHomeEnabled() and setDisplayShowTitleEnabled() on ActionBar, which you get via a call to getActionBar().




回答2:


If you want to do it the XML way, then define a style (XML file) in the /res/values-v11/ folder with the following contents:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTheme" parent="android:style/Theme.Holo">
        <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
    </style>

    <style name="MyActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:displayOptions"></item>
    </style>
</resources>

In your AndroidManifest.xml set the theme defined above for your activity:

<activity
    ...
    android:theme="@style/MyTheme">
    ...
</activity>

This will remove the icon and the title and only display the action items. If you just want the title to be displayed, the use:

<item name="android:displayOptions">showTitle</item>

Or just the application logo:

<item name="android:displayOptions">showHome</item>

Or both (default)

<item name="android:displayOptions">showHome|showTitle</item>

Other options are available too, like: showCustom, useLogo, homeAsUp




回答3:


Try

getActionBar.setIcon(R.color.transparent);



回答4:


This will help you:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);

        //the rest of your code...
}



回答5:


actionBar.setIcon(R.color.transparent);

actionBar.setTitle("");



回答6:


Try this in onCreate()

ActionBar actionbar=getSupportActionBar();
actionbar.setDisplayHomeAsUpEnabled(false);
actionbar.setIcon(android.R.color.transparent);

user android.R.color.transparent




回答7:


Try this combination

    getSupportActionBar().setHomeButtonEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setIcon(R.color.transparent);
    getSupportActionBar().setDisplayShowTitleEnabled(true)



回答8:


If you are looking to simply remove the entire actiobar, you can try the hide method for actionBars:

getActionbar().hide();


来源:https://stackoverflow.com/questions/5720715/remove-application-icon-and-title-from-honeycomb-action-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!