ActionToggle图像未显示

时间:2015-03-24 09:54:27

标签: android android-actionbar navigation-drawer

我正在实施ActionTogglebutton以显示抽屉。虽然抽屉显示单击切换按钮但是图像或切换按钮位置上没有显示

这是我的代码

actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.drawable.kooveicon) {
    public void onDrawerClosed(View view) {
        getActionBar().setTitle(getTitle());
        getActionBar().setDisplayShowHomeEnabled(false);
        getActionBar().setDisplayShowTitleEnabled(true);

        getSupportActionBar().setTitle("Closed");
        invalidateOptionsMenu();
    }

    public void onDrawerOpened(View drawerView) {
        getSupportActionBar().setDisplayShowHomeEnabled(false);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
      getSupportActionBar().setTitle("Browse Items");
        invalidateOptionsMenu();

    }
};

1 个答案:

答案 0 :(得分:0)

更新您的代码,如下所示:

        actionBar = getSupportActionBar();
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.my_drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        mDrawerToggle.setDrawerIndicatorEnabled(true);
        mDrawerLayout.setDrawerListener(mDrawerToggle);

在你的课程中添加另一种方法 onPostCreate() [这是抽屉指示动画]

@Override
protected void onPostCreate(Bundle savedInstanceState)
{
    super.onPostCreate(savedInstanceState);
    mDrawerToggle.syncState();
}

希望这有帮助!