如何设置Android微调器弹出式样?

Tim*_*Sim 7 android android-spinner android-styles

我已经设定

<item name="android:spinnerMode">dialog</item>
Run Code Online (Sandbox Code Playgroud)

所以当我点击微调器时,我会弹出一个弹出窗口.但是那个弹出窗口是带有白色文本的灰色,我似乎无法改变任何颜色.如何设置此对话框的样式?

我尝试了以下一些疯狂的临时颜色,看看有什么变化,但没有任何变化.

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:dialogTheme">@style/SpinnerDialog</item>
    <item name="android:alertDialogTheme">@style/SpinnerAlertDialog</item>
</style>

<style name="SpinnerDialog" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:popupBackground">#ff00ff</item>
    <item name="colorPrimary">#ff00ff</item>
    <item name="colorPrimaryDark">#ffff00</item>
    <item name="colorAccent">#ff0000</item>
</style>

<style name="SpinnerAlertDialog" parent="Theme.AppCompat.Dialog">
    <item name="colorPrimary">#00ffff</item>
    <item name="colorPrimaryDark">#00ff00</item>
    <item name="colorAccent">#0000ff</item>
</style>
Run Code Online (Sandbox Code Playgroud)

有一堆类似的问题,但它们都处理下拉列表或古老版本的Android或只是不工作.

PN1*_*N10 9

而不是使用theme或style.xml来更改对话框的弹出背景颜色.

为什么不尝试这个?在你的布局xml中

 <Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:spinnerMode="dialog"
    android:popupBackground="#yourcolor"/>
Run Code Online (Sandbox Code Playgroud)

既然你尝试添加主题它没有任何改变.这将很容易实现..不是吗?

希望这可以帮助!!!

  • 这不起作用.当spinner模式设置为dialog时,`popupBackgroundColor`会被忽略,就像文档说的那样. (7认同)

Abh*_*ain 4

您可以使用自定义布局来实现此目的。

Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
        R.id.custom_spinner_item, yourItemList);
adapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item);
spinner.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

您应该已准备好自定义布局:

  • R.id.custom_spinner_item对于微调器中的项目。
  • R.layout.custom_spinner_dropdown_item对于微调器下拉项。

  • 我没有使用下拉菜单。我只想更改弹出窗口的背景颜色,而不更改任何项目。 (2认同)