1

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.

schlingel
  • 8,382
  • 7
  • 31
  • 60
Parthiban M
  • 1,096
  • 1
  • 9
  • 29

4 Answers4

3

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();

Pooja
  • 2,287
  • 16
  • 36
0

You can try like this:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    super.onCreate(savedInstanceState);

It should be called before setContentView() method in onCreate() method of Activity.

Rajan Bhavsar
  • 1,969
  • 9
  • 24
0

You should add requestWindowFeature(Window.FEATURE_NO_TITLE); before super.onCreate(savedInstanceState);

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
Aniruddha
  • 4,421
  • 1
  • 19
  • 38
0

This should work.Put this after super.onCreate(savedInstanceState);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

All the best.

Prakhar
  • 738
  • 6
  • 22