Search code examples
androidandroid-actionbarandroid-5.0-lollipop

Hide "ActionBar" on API 21


I've updated Androïd SDK yesterday, so I have change the targetSdkVersion to 21. Since I did this update I am unable to hide the "ActionBar" (which is not realy one) on an Activity.

In my application there is just one Activity that I want to display without title bar and without actionbar.

All activities used this theme:

<style name="AppBaseTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

and I tried this in the concerned activity:

@Override
protected void onCreate(final Bundle savedInstanceState) {
    this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
}

but it doesn't work. I also tried : getSupportActionBar().hide() but getSupportActionBar() returns null

Do you have any idea?


Solution

  • Use getActionBar().hide() like this.

    public class MyActivity extends ActionBarActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity);
    
            this.getActionBar().hide();
        }
    }