Reputation: 123
I used this code in my oncreate function to open the navigation drawer by pressing the app icon.
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
(DrawerLayout) findViewById(R.id.left_drawer), /* DrawerLayout object */
getResources().getDrawable(R.drawable.ic_drawer), /* nav drawer icon to replace 'Up' caret */
getString(R.string.drawer_open), /* "open drawer" description */
getString(R.string.drawer_close) /* "close drawer" description */
) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
getActionBar().setTitle(R.string.title_activity_add);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(R.string.drawer_title);
}
};
Now it says "The constructor ActionBarDrawerToggle(AddActivity, DrawerLayout, Drawable, String, String) is undefined". I have imported android.support.v4.app.ActionBarDrawerToggle. Where's the problem?
Upvotes: 1
Views: 3389
Reputation: 396
Just to echo @CommonsWare answer. Instead of findViewById(R.id.left_drawer)
just do R.id.left_drawer
So the final result would look like this:
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
)
Upvotes: 0
Reputation: 1006789
The constructor is not ActionBarDrawerToggle(AddActivity, DrawerLayout, Drawable, String, String)
. It is ActionBarDrawerToggle(Activity, DrawerLayout, int, int, int)
. Change your last three parameters to be the resource IDs, not the results of referencing the resource IDs.
Upvotes: 4