Search code examples
androidandroid-themematerial-components-android

How to set background color of exposed dropdown PopupWindow?


I'm using an exposed dropdown from material design components. It's an AutoCompleteTextView within a TextInputLayout which basically acts like a spinner. You give it an adapter and it pops up a PopupWindow on click.

The PopupWindow background is a dark gray. I'd like to change it to white. I've tried this via theming to no avail:

<style name="PopupWindow">
    <item name="popupMenuBackground">@color/white</item>
    <item name="android:popupBackground">@color/white</item>
    <item name="android:windowBackground">@color/white</item>
</style>

I've also tried calling this on the AutoCompleteTextView:

autoCompleteTextView.setDropDownBackgroundResource(R.color.white);

This actually worked. However, if I open the dropdown when the keyboard is open, the background turns dark gray again. It's only when the keyboard is dismissed that the background is white.

Any idea how to solve this? Surely there has to be a theme attribute that I can override to make the PopupWindow background white?


Solution

  • Found the solution thanks to this post: https://medium.com/@rmirabelle/there-is-no-material-design-spinner-for-android-3261b7c77da8

    Just override colorSurface in your theme:

    <item name="colorSurface">@color/white</item>