Android DrawerLayout没有显示正确的指示符图标 - 代码日志

Android DrawerLayout没有显示正确的指示符图标

我正在尝试使用新的DrawerLayout列表。问题是虽然我设置了抽屉监听器,但是操作栏上的指示灯仍然是箭头图标,而不是我打算绘制的3行图标。以下是OnCreate功能:

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);
}

谁能帮忙?

更新:我发现问题。我添加了onPostCreate函数如下,现在它的工作。

protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}
你需要从onPostCreate()来调用ActionBarDrawerToggle对象的syncState()

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}
http://stackoverflow.com/questions/17825629/android-drawerlayout-doesnt-show-the-right-indicator-icon

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:Android DrawerLayout没有显示正确的指示符图标