且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Android的实施DrawerArrowToggle appcompat V7 21库

更新时间:2023-01-27 19:12:09

首先,你应该知道现在 android.support.v4.app.ActionBarDrawerToggle 是德precated。

First, you should know now the android.support.v4.app.ActionBarDrawerToggle is deprecated.

您必须替换与 android.support.v7.app.ActionBarDrawerToggle

下面是我的榜样,我用的是新的工具栏来替换动作条

Here is my example and I use the new Toolbar to replace the ActionBar.

MainActivity.java

public class MainActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
        this,  mDrawerLayout, mToolbar,
        R.string.navigation_drawer_open, R.string.navigation_drawer_close
    );
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mDrawerToggle.syncState();
}

styles.xml

<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>

您可以阅读AndroidDocument#DrawerArrowToggle_spinBars

这属性是实现菜单对箭头动画的关键。

This attribute is the key to implement the menu-to-arrow animation.

公共静态INT DrawerArrowToggle_spinBars

  有无拉杆应该旋转或不能在过渡
  必须是一个布尔值,无论是真或假。

public static int DrawerArrowToggle_spinBars

Whether bars should rotate or not during transition
Must be a boolean value, either "true" or "false".

所以,你设置这样:&LT;项目名称=spinBars&GT;真&LT; /项目&GT;

这样动画可以presented。

Then the animation can be presented.

希望这可以帮助你。