3 回答
TA贡献1797条经验 获得超6个赞
要回答问题的更新部分:要设置抽屉图标/箭头的样式,您有两种选择:
设计箭头本身
为此,请drawerArrowStyle在主题中覆盖,如下所示:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> <item name="drawerArrowStyle">@style/MyTheme.DrawerArrowToggle</item></style><style name="MyTheme.DrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle"> <item name="color">@android:color/holo_purple</item> <!-- ^ this will make the icon purple --></style>
这可能不是你想要的,因为ActionBar本身应该与箭头具有一致的样式,所以,最有可能的是,你想要选项二:
主题ActionBar /工具栏
使用您自己的主题(您可能应该从中派生出来)覆盖全局应用程序主题的android:actionBarTheme(actionBarThemefor appcompat)属性,ThemeOverlay.Material.ActionBar/ThemeOverlay.AppCompat.ActionBar如下所示:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> <item name="actionBarTheme">@style/MyTheme.ActionBar</item></style><style name="MyTheme.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar"> <item name="android:textColorPrimary">@android:color/white</item> <!-- ^ this will make text and arrow white --> <!-- you can also override drawerArrowStyle here --></style>
这里一个重要的注意事项是,当使用自定义布局Toolbar而不是库存ActionBar实现时(例如,如果您使用DrawerLayout- NavigationView- Toolbar组合来实现在半透明状态栏下可见的材质样式抽屉效果),该actionBarTheme属性显然不是自动拾取(因为它意味着由AppCompatActivity默认值处理ActionBar),因此对于您的自定义,Toolbar请不要忘记手动应用您的主题:
<!--inside your custom layout with DrawerLayout and NavigationView or whatever --><android.support.v7.widget.Toolbar ... app:theme="?actionBarTheme">
- ThemeOverlay.AppCompat.ActionBar如果在派生主题中设置属性,这将解析为AppCompat的默认值或覆盖。
PS关于drawerArrowStyle覆盖和spinBars属性的一点评论- 许多消息来源建议应该设置true为获取抽屉/箭头动画。spinBars事实上true ,默认情况下,它在AppCompat中(检查Base.Widget.AppCompat.DrawerArrowToggle.Common样式),您根本不必重写actionBarTheme以使动画正常工作。即使您覆盖它并将属性设置为动态,也可以获得动画false,它只是一个不同的,不那么圆润的动画。这里重要的是使用ActionBarDrawerToggle,它是花哨的动画drawable的东西。
- 3 回答
- 0 关注
- 820 浏览
添加回答
举报
