Styling a Spinner, appcompat, material

2019-06-17 02:57发布

问题:

So my app theme extends from AppCompat's Material Light theme with Dark Action Bar.

I applied an accent color.

Now I am trying to use a Spinner on a dark backround and because of the theme, the spinner has a dark gray arrow which changes to accent color when pressed.

How can I make this spinner's arrow white so that it is prominent on a dark background?

Here's the image of the Spinner:

回答1:

If you want to apply same spinner style app wide, then in your values/styles.xml, override spinnerStyle with your custom style, which derives from an appcompat type and override android:background:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:spinnerStyle">@style/AppSpinner</item>
</style>

<style name="AppSpinner" parent="Widget.AppCompat.Spinner">
    <item name="android:background">@drawable/your_spinner_background</item>
</style>

If you need a quick way to generate a spinner background, try android-holo-colors, choose Colored Spinner and supply your accent color.



回答2:

So the support library 22.1 enables use of android:theme attribute on views. That should help here.



回答3:

with android:background you can specify your own background resource. I find the arrow rather useless (tapping the spinner brings dropdown menu even without arrow) so if you don't want to draw a custom arrow image, just leave the background black or transparent.