如何从Android appcompat v7 21库设置DrawerArrowToggle的样式

Big*_*dad 31 android android-5.0-lollipop

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

该库在这里实现和风格也对我很好,但由于程序兼容性V7库有它怎么能称呼?

我使用v7 DrawerToggle实现了这个功能.但是我无法设计它.请帮忙

我在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>
Run Code Online (Sandbox Code Playgroud)

我把它添加到我的样式中并且没有用.也添加到我的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>
Run Code Online (Sandbox Code Playgroud)

但是崩溃并且在这样做时说颜色类型错误.我错过了什么?

Chr*_*nes 97

以下适用于我:

<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>
Run Code Online (Sandbox Code Playgroud)


mar*_*XII 24

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

所以我Widget.AppCompat.DrawerArrowTogglevalues.xmlappcompat-v7中打开了样式.

<style name="Widget.AppCompat.DrawerArrowToggle" parent="Base.Widget.AppCompat.DrawerArrowToggle">
    <item name="color">?attr/colorControlNormal</item>
</style>
Run Code Online (Sandbox Code Playgroud)

所以我创建了特殊主题:

<style name="Toolbar_Theme">
    <item name="colorControlNormal">@android:color/black</item>
</style>
Run Code Online (Sandbox Code Playgroud)

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

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    app:theme="@style/Toolbar_Theme" />
Run Code Online (Sandbox Code Playgroud)

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

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