Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 3.2 remove title from action bar

Tags:

android

I'm working with eclipse, android 3.2. and a virtual machine running android x86. (v3.2)

I use the Holo theme and I want to remove the action bar title and icon. So I do

@Override
public void onCreate(Bundle savedInstanceState)
{
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);
}

It's working fine but ...

When the application start, I first show the title and icon and only after I see them disappearing. So it's not very beautiful.

If I use debug, I can see It's only when I leave the onCreate that the setDisplayShowTitleEnabled takes effect.

So is there a way to hide title and icon before the activity is shown ?

Thanks.

like image 337
tweetysat Avatar asked Feb 17 '12 10:02

tweetysat


2 Answers

In your Manifest

<activity android:name=".ActivityHere"
     android:label="">
like image 135
easycheese Avatar answered Oct 21 '22 22:10

easycheese


I got around this by setting the "NoActionBar" holo theme in the android manifest and then setting the normal holo theme in onCreate().

Step 1: In styles.xml, added a custom theme resource.

<resources>
    <style name="ActionBar.CustomTheme" parent="@android:style/Widget.Holo.ActionBar"/>
    <style name="CustomTheme" parent="@android:style/Theme.Holo">
        <item name="android:actionBarStyle">@style/ActionBar.CustomTheme</item>
    </style>
</resources>

Step 2: In my android manifest file I set the theme for the application and the "NoActionBar" holo theme for the startup activity.

<application
  android:theme="@style/CustomTheme
  ...

<activity
  android:name="MainActivity"
  android:theme="@android:style/Theme.Holo.NoActionBar">
  ...

Step 3: In the startup activity's onCreate()...

@Override
public void onCreate()(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setTheme(R.style.CustomTheme); // Set the custom theme which has the action bar.
    ActionBar actionBar = getActionBar();
    ...
like image 9
Anubisoft Avatar answered Oct 21 '22 22:10

Anubisoft