安卓下拉菜单背景颜色如何修改

22
我想在不改变下拉菜单自身背景颜色的情况下,改变一个选择器(Spinner)的下拉菜单背景颜色(它是透明的)。这是否可能?
3个回答

70

没错,这是可能的。在XML中使用android:popupBackground或在代码中使用setPopupBackgroundResource(int)来设置Spinner的弹出背景。


5
要更改下拉列表的背景颜色,请在您的styles.xml中的主题中添加android:colorBackground参数。
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:colorBackground">#ff0000</item>
</style>


因此,整体风格得以保留:按下时的效果、圆角等。
截图:

enter image description here enter image description here


0

在使用 Material Design 3 时,响应式属性是:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接