使用ActionBarDrawerToggle和appcompat v7更改导航抽屉homeAsUpIndicator

时间:2015-03-04 14:24:47

标签: android android-actionbar navigation-drawer

我正在尝试将操作栏的主页更改为向上指示符。现在它显示一个箭头(打开时)和3个条纹(关闭时):

navigation drawer closed navigation drawer opened

我想用自定义drawable替换此箭头。以下代码不起作用:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setLogo(getResources().getDrawable(R.drawable.actionbar_logo));
    getSupportActionBar().setDisplayUseLogoEnabled(true);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(
            this,                  /* host Activity */
            mDrawerLayout,         /* DrawerLayout object */
            R.string.app_name,  /* "open drawer" description for accessibility */
            R.string.app_name  /* "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()
        }
    };
    mDrawerToggle.setHomeAsUpIndicator(getResources().getDrawable(R.drawable.actionbar_logo));
    mDrawerLayout.setDrawerListener(mDrawerToggle);

如果我在样式中使用<item name="displayOptions">useLogo|showHome|showTitle</item>,它会显示除原始homeAsUpIndicator之外的自定义drawable,而我想要的是替换它

我怎样才能做到这一点?谢谢!

0 个答案:

没有答案