Two ways to hide an Android ActionBar on an Activity

If you want to hide the Android ActionBar on an Activity, it looks like there are at least two approaches.

First, add the android:theme="@android:style/Theme.NoTitleBar" entry to the activity’s definition in AndroidManifest.xml:

<activity
    android:name=".PlayAGameActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar" >
</activity>

A second approach is to add this code in the Activity (or Fragment) onCreate method:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();

I just tried both approaches in an Android app I’m working on, and I can verify that they both work.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.