AppCompatActivity ActionbarDrawerToggle

AppCompatActivity ActionbarDrawerToggle

我最近将我的一个 activity class 从继承 ActionbarActivity(因为这个 class 现在在新的 android 版本中已经过时)更改为 AppCompatActivity。我可以在更改之前指定我希望导航抽屉使用的图标,但在新的 ActionBarDrawerToggle 之后不允许这样做。

我能够实现这个并显示抽屉图标,我现在遇到的问题是如何将图标(三行图标)的颜色从黑色更改为白色。

工具栏中项目的颜色取决于主题。

如果您使用 Theme.AppCompat(深色主题),图标将为白色。如果您使用 Theme.AppCompat.Light,图标将是黑色的。还有Theme.AppCompat.Light.DarkActionBar.

More about using appcompat 图书馆。

这是使用 Theme.AppCompat.Light.DarkActionBar 的示例(带有深色操作栏和操作栏中的白色图标的浅色主题)

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

ActionBarDrawerToggle 的颜色可以更改为您想要的任何颜色。
请看下面的例子:

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <!-- ActionBarDrawerToggle colour -->
        <item name="drawerArrowStyle">@style/DrawerToggle</item>
    </style>

    <style name="DrawerToggle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
        <item name="color">@color/my_super_colour</item>
    </style>

    <color name="my_super_colour">#00ff00</color>

</resources>