FragmentActivity with ActionBarDrawerToggle

1

I would like to create a Drawer with an ActionBarDrawerToggle . I'm following this tutorial ! My only change is that I am extending FragmentActivity and not a Activity as the example.
When I execute, a NullPointer occurs on the following line:

getActionBar().setDisplayHomeAsUpEnabled(true);

Because getActionBar() is null !. Would anyone know how to put ActionBarDrawerToggle into FragmentActivity ?

    
asked by anonymous 13.07.2015 / 15:07

1 answer

2

I think you're using the v7 appcompat library . To access ActionBar your Activity should inherit from ActionBarActivity or rather from AppCompactActivity since ActionBarActivity was considered obsolete.

You can then get a reference to ActionBar using:

ActionBar actionBar = getSupportActionBar(); 

AppCompactActivity is a FragmentActivity with ActionBar support.

    
13.07.2015 / 15:40