1

I am using a spinner like this:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, templateTitles);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

mySpinner.setAdapter(adapter);

And my manifest is:

<application
    android:name="MyApplication"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme" >

Where the style is:

<style name="AppTheme" parent="android:Theme.WithActionBar">
        <item name="android:textColor">#000000</item>
</style>

The problem is that when you click on spinner and display the dialog with selection items, the background is white and the text is invisible (because it is white). When you click and hold on a selection, then the text appears as it changes to black.

Why wouldn't the text default to black/grey to show? How can I overcome this issue? This issue seemed to happen only on devices running API 6 or above. I guess the older devices showed the color properly.

Any suggestion? Thanks.

EDIT: This only happens when the spinner is on a dialog.

ccy
  • 1,735
  • 16
  • 19
Snake
  • 14,228
  • 27
  • 117
  • 250
  • @CommonsWare, maybe you know the answer for this as answered a similar question? The mContext being passed here is an activity context – Snake Apr 07 '17 at 04:31

3 Answers3

1

Create style like this

<style name="spinnerItemStyle" parent="@android:style/Widget.Holo.DropDownItem.Spinner">
    <item name="android:textColor">#000000</item>
</style>  

Apply to your spinner

<Spinner
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/spinnerItemStyle"/>  

EDIT:-

Change parent style to @style/Widget.AppCompat.Spinner

Murli Prajapati
  • 8,833
  • 5
  • 38
  • 55
  • It didn't work unfortunetly! still white text . Keep in mind that the spinner is sitting on a dialog (if it makes a difference) – Snake Apr 07 '17 at 04:05
  • Look at here http://stackoverflow.com/questions/32066277/how-do-i-set-a-different-theme-for-a-spinners-dropdown – Murli Prajapati Apr 07 '17 at 04:33
0

Try to apply a style to your spinner

<Spinner
    android:id="@+id/spinner"
    style="@android:style/Widget.Holo.Light.Spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:spinnerMode="dropdown" />
humazed
  • 74,687
  • 32
  • 99
  • 138
0

I found the solution for this problem. I needed to do this in code

ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, templateTitles){
            @Override
            public View getDropDownView(int position, View convertView,
                                        ViewGroup parent) {
                View view = super.getDropDownView(position, convertView, parent);
                TextView tv = (TextView) view;

                // Set the Text color
                tv.setTextColor(Color.BLACK);

                return view;
            }
        };
Snake
  • 14,228
  • 27
  • 117
  • 250