设置 Toolbar(ActionBar) 上的按钮颜色

原文地址:
https://stackoverflow.com/a/29536902
https://stackoverflow.com/a/27754099
[your_layout.xml]

1
2
3
4
5
<android.support.v7.widget.Toolbar
<!-- leave the theme stuff out of here -->
style="@style/MyToolbarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Styles / Themes in styles.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- your other attributes -->
<!-- following is used to tint the checkbox - purple for demo purpose -->
<item name="colorControlNormal">#2196F3</item>
</style>
<style name="MyToolbarStyle">
<item name="android:minHeight">?actionBarSize</item>
<item name="android:background">?colorPrimary</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/MyToolbarTheme</item>
</style>
<style name="MyToolbarTheme">
<!-- Used to tint the back arrow, menu and spinner arrow -->
<item name="colorControlNormal">#FFF</item>
</style>

Result

Note: I made the checkbox purple for demo purpose

Change arrow color of Spinner

1) In styles.xml, add the following style:

1
2
3
4
5
6
7
8
<style name="ActionBarThemeOverlay" parent="">
<item name="android:textColorPrimary">#ffffff</item>
<item name="colorControlNormal">#ffffff</item>
<item name="colorControlHighlight">#ff33b5e5</item>
</style>
<style name="Widget.MyTheme.HeaderBar.Spinner" parent="Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:theme">@style/ActionBarThemeOverlay</item>
</style>

2) In the layout, where you use the Spinner (in your case with Toolbar), add the style to your spinner:

1
2
3
4
5
6
<Spinner
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_spinner"
style="@style/Widget.MyTheme.HeaderBar.Spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

坚持原创及高品质技术分享,您的支持将鼓励我继续创作!