I am trying to get my Action Bar to display an icon and not display any title while both states of the Navigation Drawer (open and closed) I read the documentation on developers android about how to modify the contents of the Action Bar when the drawer is visible. As the page said, I created an instance of ActionBarDrawerToggle
and set the icon and set title to null. But still I am not able to see any icon and the app title appears as soon as I draw out the Navigation drawer. The following is the code I have used in onCreate
of my activity
mToggle = new ActionBarDrawerToggle(
this,
drawerLayout,
R.string.drawer_open_or_close,
R.string.drawer_open_or_close) {
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getActionBar().setTitle(R.string.drawer_open_or_close);
getActionBar().setIcon(R.drawable.icon_144);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getActionBar().setTitle(R.string.drawer_open_or_close);
getActionBar().setIcon(R.drawable.icon_144);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
As you can see, I have set the Action bar title to R.string.drawer_open_or_close
, which is an empty string, during both completely open and completely closed state. I have set the app icon in both cases as well. What am I missing here?
Edit: I had forgotten to set the drawer toggle as DrawerListener
, which I did
drawerLayout.setDrawerListener(mToggle);
Now when I open Navigation drawer, the app force closes and the log cat says java.lang.NullPointerException
at
getActionBar().setTitle(R.string.drawer_open_or_close);
0 comments:
Post a Comment