如何动画汉堡到箭头与Appcompat

如何动画汉堡到箭头与Appcompat

本文介绍了如何动画汉堡到箭头与Appcompat V7 21,工具栏和DrawerLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用android.support.v7.widget.Toolbar与android.support.v4.widget.DrawerLayout。它工作正常,汉堡图标在导航抽屉被关闭,箭头图标在抽屉打开。我想禁用抽屉和在应用程序中的一些事件动画汉堡图标变成箭头。我试图锁定模式设置为关闭,但v7.app.ActionBarDrawerToggle仍呈现汉堡和它打开的抽屉。

I am using the android.support.v7.widget.Toolbar with a android.support.v4.widget.DrawerLayout. It works fine, the Burger icon is shown when the Navigation Drawer is closed, and the Arrow icon is shown when the Drawer is open.I want to disable the drawer and animate the Burger icon into Arrow on some event in the app. I have tried to set the lock mode to closed, but the v7.app.ActionBarDrawerToggle is still showing the Burger and it opens the Drawer.

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

任何想法?谢谢!

更新:

没有,我可以改变图标的​​状态,我可以启用/禁用的抽屉,但动画不工作这种方法:

No I can change the state of the icon and I can enable/disable the drawer, but the animations are not working with this approach:

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    Toolbar toolbar = (Toolbar) findViewById(R.id.application_toolbar);
    setSupportActionBar(toolbar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.string1, R.string.string2) {
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }
    };

    //mDrawerLayout.setDrawerListener(mDrawerToggle); // not needed
    ...
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case android.R.id.home:
            if (mDrawerLayout.getDrawerLockMode(GravityCompat.START) == LOCK_MODE_UNLOCKED) {
                showDrawer();
            } else {
                handleBackButtonPress(); // On this stage the home button is a <-
            }
    }
    ...
}

private void setDrawerState(boolean isEnabled) {
    if (isEnabled) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
        mDrawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_UNLOCKED);
        mDrawerToggle.syncState();

    } else {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        mDrawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        mDrawerToggle.syncState();
    }
}

抽屉来在工具栏的顶部。

The drawer comes on the top of the Toolbar.

推荐答案

看一看这里,它描述了如何解决这个问题。

Have a look here, it describes how you solve it.

http://stackoverflow.com/a/26447144

的重要组成部分如下:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>

这篇关于如何动画汉堡到箭头与Appcompat V7 21,工具栏和DrawerLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:03