5

So I was looking at google's api demos for action bars and they have this

// The Action Bar is a window feature. The feature must be requested
    // before setting a content view. Normally this is set automatically
    // by your Activity's theme in your manifest. The provided system
    // theme Theme.WithActionBar enables this for you. Use it as you would
    // use Theme.NoTitleBar. You can add an Action Bar to your own themes
    // by adding the element <item name="android:windowActionBar">true</item>
    // to your style definition.
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

but when I tried to add the last line of code getWindow().requestFeature(Window.FEATURE_ACTION_BAR); My app just dies on start up. So what does it really do?

domshyra
  • 933
  • 3
  • 11
  • 28
  • 2
    read your log cat and post a copy of the exception that is causing your app to crash. – FoamyGuy Nov 30 '11 at 00:53
  • 8
    Most likely, you are calling it too late. `requestFeature()` needs to be called before `setContentView()`. – CommonsWare Nov 30 '11 at 01:07
  • @CommonsWare Yeah that was the reason it wasn't working. Thanks. It was weird because it only generated an error in the emulator and not a syntax error. – domshyra Nov 30 '11 at 02:49

2 Answers2

1

The secret is the order of the callings.The requestfeature must be called before fill nothing. I do it in this order and works fine:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.your_activity_layout);
Ernesto Vega
  • 470
  • 6
  • 12
0

I know this is very late, did you try

requestWindowFeature(Window.FEATURE_ACTION_BAR)
Eswar Yaganti
  • 2,536
  • 1
  • 20
  • 22