I'm trying to use the new DrawerLayout for a list. The problem is though I set the drawer listener, the indicator on the actionbar is still the arrow icon instead of the 3-line icon which I intends to draw. The following is the OnCreate function:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_front_page);
// Swiping Pager set up
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// Sliding Drawer set up
mHabitContract = new HabitsContract(this);
mDrawerLayout = (DrawerLayout) findViewById(R.id.front_page_layout);
mDrawerList = (ListView) findViewById(R.id.habit_list);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerList.setAdapter(new HabitAdapter(mHabitContract.GetHabitItems(), this));
// Fixme: Indicator image doesn't show up
mDrawerToggle = new ActionBarDrawerToggle(
this, /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.drawable.ic_navigation_drawer, /* nav drawer image to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */
) {
public void onDrawerClosed(View view) {
//getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
//getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
// Action Bar set up
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
}
Can anyone help?
Update: I found the problem. I added the onPostCreate function as follows, and now it's working.
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity> . Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.
The navigation drawer is a UI panel that shows your app's main navigation menu. The drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen.
You need to syncState()
call of your ActionBarDrawerToggle
object from onPostCreate()
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
For those who are searching this or came here looking for an answer: you have to use to DrawerToggle support.v7. Following how I use it:
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_opened, R.string.drawer_closed){
public void onDrawerClosed(View view){
//actionBar.setTitle(mTitle);
invalidateOptionsMenu(); // crea la llamada para onPrepareOptionsMenu
}
public void onDrawerOpened(View view){
//actionBar.setTitle(mDrawerTitle);
invalidateOptionsMenu(); // crea la llamda para onPrepareOptionsMenu
}
};
This works fine and has an animation that rocks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With