【问题标题】:use of syncState() in ActionBarDrawerToggle在 ActionBarDrawerToggle 中使用 syncState()
【发布时间】:2014-03-13 21:45:03
【问题描述】:

我使用ActionBarDrawerToggle 类将DrawerLayout 的功能和ActionBar 框架结合在一起,以实现导航抽屉的推荐设计。

Android 开发者网站说的是:

在 onRestoreInstanceState 发生后,从您的 Activity 的 onPostCreate 调用 syncState() 以将指示器与链接的 DrawerLayout 的状态同步。

但我没有得到syncState() 方法的实际作用?

请尽可能简单地解释。

【问题讨论】:

    标签: android navigation-drawer


    【解决方案1】:

    DrawerLayout 指示器是ActionBar 主页图标左侧的小图标(见图)

    ActionBarDrawerToggle.syncState被调用,根据DrawerLayout的实例状态恢复后,DrawerLayout是打开还是关闭,正确偏移这个指标。

    【讨论】:

      【解决方案2】:

      从您的活动的onPostCreate 调用syncState() 以在活动通过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();
      }
      

      【讨论】:

        【解决方案3】:

        从你的 Activity 的onPostCreate 调用,以在onRestoreInstanceState 发生后将指示器图标与链接的 DrawerLayout 的状态同步。

        例如

        protected void onPostCreate(Bundle savedInstanceState)
        {
            super.onPostCreate(savedInstanceState);
            this.navDrawerToggle.syncState();
        }
        

        【讨论】:

          猜你喜欢
          • 2020-12-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多