Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use of syncState() in ActionBarDrawerToggle

I'm using ActionBarDrawerToggle class to tie together the functionality of DrawerLayout and the framework ActionBar to implement the recommended design for navigation drawers.

What Android developer site says is:

Call syncState() from your Activity's onPostCreate to synchronize the indicator with the state of the linked DrawerLayout after onRestoreInstanceState has occurred.

But I'm not getting what syncState() method actually does?

Please explain it as simple as possible.

like image 491
user3371398 Avatar asked Mar 13 '14 21:03

user3371398


2 Answers

The DrawerLayout indicator is the little icon to the left of the ActionBar home icon (see picture)

ActionBarDrawerToggle.syncState is called properly offset this indicator based on whether or not the DrawerLayout is open or closed after the instance state of the DrawerLayout has been restored.

DrawerLayout indicator

like image 106
adneal Avatar answered Oct 21 '22 16:10

adneal


Call syncState() from your activity's onPostCreate to set the state of the indicator based on whether the drawerlayout is in open or closed state once the activity has been restored with onRestoreInstanceState.

protected void onPostCreate(Bundle savedInstanceState) {
    // TODO Display the navigation drawer icon on action bar when there state has changed 
    super.onPostCreate(savedInstanceState);
    drawerListener.syncState();
}
like image 6
Dhruv Raval Avatar answered Oct 21 '22 15:10

Dhruv Raval