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

2023-09-12 21:30:03 作者:尘已落定各自安

所以,现在的Andr​​oid 5.0发布我想知道如何实现的动画动作条的图标。

So now that Android 5.0 was released i was wondering how to implement the animated actionbar icons.

该库 实现它为我好,但由于appcompat V7库有它如何能实现?

This library here implements it fine for me but since the appcompat v7 library has it how can it be implemented?

该库引用它的themes.xml

The library references it in themes.xml

 <item name="drawerArrowStyle">@style/Widget.AppCompat.DrawerArrowToggle</item>

在这种风格的

Under this style

 <style name="Base.V7.Theme.AppCompat" parent="Platform.AppCompat">

更新

我使用V7 DrawerToggle此实现。不过,我不能设置样式。请帮助

I got this implemented using the v7 DrawerToggle. However I cannot style it. Please Help

我在V7 styles_bas​​e.xml

I found the styling for it in the v7 styles_base.xml

<style name="Base.Widget.AppCompat.DrawerArrowToggle" parent="">
    <item name="color">?android:attr/textColorSecondary</item>
    <item name="thickness">2dp</item>
    <item name="barSize">18dp</item>
    <item name="gapBetweenBars">3dp</item>
    <item name="topBottomBarArrowSize">11.31dp</item>
    <item name="middleBarArrowSize">16dp</item>
    <item name="drawableSize">24dp</item>
    <item name="spinBars">true</item>
</style>

我说这对我的风格,并没有工作。同时加入到我的attr.xml

I added this to my styles and did not work. Also added to my attr.xml

<declare-styleable name="DrawerArrowToggle">
    <!-- The drawing color for the bars -->
    <attr name="color" format="color"/>
    <!-- Whether bars should rotate or not during transition -->
    <attr name="spinBars" format="boolean"/>
    <!-- The total size of the drawable -->
    <attr name="drawableSize" format="dimension"/>
    <!-- The max gap between the bars when they are parallel to each other -->
    <attr name="gapBetweenBars" format="dimension"/>
    <!-- The size of the top and bottom bars when they merge to the middle bar to form an arrow -->
    <attr name="topBottomBarArrowSize" format="dimension"/>
    <!-- The size of the middle bar when top and bottom bars merge into middle bar to form an arrow -->
    <attr name="middleBarArrowSize" format="dimension"/>
    <!-- The size of the bars when they are parallel to each other -->
    <attr name="barSize" format="dimension"/>
    <!-- The thickness (stroke size) for the bar paint -->
    <attr name="thickness" format="dimension"/>
</declare-styleable>

但崩溃,并表示颜色类型的错误这样做的时候。我在想什么?

But crashes and says color type error when doing so. What am i missing?

推荐答案

首先,你应该知道现在 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.

希望这可以帮助你。

 
精彩推荐
图片推荐