Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to style Android spinner popup?

I have set

<item name="android:spinnerMode">dialog</item>

and so when I tap the spinner, I get a popup. But that popup is grey with white text and I can't seem to change any of the colors. How do I style this dialog?

I tried the following with some crazy temporary colors to see what changes but nothing changes.

<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>

There are a bunch of similar questions, but they all either deal with dropdowns or ancient versions of Android or just don't work.

like image 763
TimSim Avatar asked Feb 19 '17 08:02

TimSim


People also ask

What is set spinner show () method?

Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it.

Who is the parent class of spinner?

Android Spinner class is the subclass of AsbSpinner class.


1 Answers

Instead of using theme or style.xml for changing the popup background color of dialog.

Why not try this?? In your layout xml

 <Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:spinnerMode="dialog"
    android:popupBackground="#yourcolor"/>

Since you tried adding theme it changes nothing.This will be easy to achieve..isn't it??

Hope this helps!!!

like image 154
PN10 Avatar answered Sep 20 '22 08:09

PN10