如何deviseAndroid appcompat v7 21库中的DrawerArrowToggle

所以,现在Android 5.0发布了,我想知道如何设置animation的动作栏图标的样式。

这个库在这里实现和风格对我来说很好,但是由于appcompat v7库有它,它如何被风格?

我用v7 DrawerToggle实现了这个function。 但是我无法devise它。 请帮忙

我在v7 styles_base.xml中find了它的样式

<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

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

但这样做时崩溃并说色彩types错误。 我错过了什么?

以下为我工作:

 <style name="MyTheme" parent="Theme.AppCompat"> <item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item> </style> <style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle"> <item name="color">@color/your_color</item> </style> 

在我的情况下,我想改变抽屉箭头和汉堡包图标的颜色。 设置抽屉箭头样式只改变了汉堡包图标的颜色。

所以我在appcompat-v7的values.xml中打开了Widget.AppCompat.DrawerArrowToggle样式。

 <style name="Widget.AppCompat.DrawerArrowToggle" parent="Base.Widget.AppCompat.DrawerArrowToggle"> <item name="color">?attr/colorControlNormal</item> </style> 

所以我创造了特别的主题:

 <style name="Toolbar_Theme"> <item name="colorControlNormal">@android:color/black</item> </style> 

并将其应用于我的工具栏如下:

 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" app:theme="@style/Toolbar_Theme" /> 

请注意,我正在使用theme 属性,而不是在我的应用主题中定义controlColorNormal 。 这种方式的颜色只适用于工具栏项目,如果我在应用程序主题中设置,那么它也会影响滚动条的颜色等。

设置colorControlNormal属性改变汉堡包和抽屉箭头的颜色。

对于任何最终在这里(像我一样)寻找一种方法来使用v7的ActionBarDrawerToggle来replace抽屉指标图标与你自己的drawable(非animation),你可以做到以下几点:

 //After instantiating your ActionBarDrawerToggle mDrawerToggle.setDrawerIndicatorEnabled(false); Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.your_custom_icon, getActivity().getTheme()); mDrawerToggle.setHomeAsUpIndicator(drawable); mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) { mDrawerLayout.closeDrawer(GravityCompat.START); } else { mDrawerLayout.openDrawer(GravityCompat.START); } } }); 

在我的情况下,操作栏的主题与在白色和黑色汉堡图标之间切换有关:

 <item name="actionBarWidgetTheme">@style/Theme.AppCompat</item> 

 <item name="actionBarWidgetTheme">@style/Theme.AppCompat.Light</item> 

你的风格名称没有父母这里的工作与Android 5和材料的主题,而不需要用appCompatreplace操作栏这是我的风格,我只需要改变颜色为白色,因为我有一个彩色的酒吧

  <style name="myTheme.DrawerArrowToggle" parent="Base.Widget.AppCompat.DrawerArrowToggle"> <item name="color">@color/white</item> </style> 

这是我的主题

 <style name="Theme_AppTheme.Light" parent="@android:style/Theme.Material.Light"> <!-- Drawer\arrow in white --> <item name="drawerArrowStyle">@style/myTheme.DrawerArrowToggle</item> 

PS。 这只是一个问题,在adroid 4.4和正常的操作栏不能很好地呈现。 而且不幸的是,从v7的nre drawerToggle不会从v4inheritance

不知道什么是确切的错误,如果你已经定义了颜色,去attrs.xmlsearchattr名称=“颜色”,并重命名或testing评论它,你可能需要改变你的自定义attr到另一个名字,不知道这是一个支持lib的问题,这对我有用