Search code examples
androidandroid-actionbar

Unable to hide action bar


I tried to create a new Android application and I tried to hide the action bar in the constructor of MainActivity, using the line requestWindowFeature(Window.FEATURE_NO_TITLE);

I've done this previously many times and there wasn't any problem in this. But when I try the same now it throws a error mentioning that "request feature must be called before adding the content"

Even I've tried adding this line in various positions but there wasn't any change in result. Can anyone help me solving this issue.


Solution

  • There are two ways to hide actionbar. I am assuming you are using Theme.AppCompat.Light style and your activity extends ActionBarActivity.

    Set below lines to your styles.xml

     <item name="windowActionBar">false</item>
    

    Or

    Set below lines in your java file.

    getSupportActionBar().hide();