bigbirduk
bigbirduk

Reputation: 23

Android Spinner Text Background Colour and Theme

I have a problem that has manifested itself since I tried to add themes to my application. At the moment I am just using themes to change the background colour of the screen. The problem is that as well as the background of the screen changing to the theme colour, the background of the text in the spinner control also changes to that colour. When the drop down is displayed the spinner control is replaced by the block background colour.

The themes are defined as follows:

<style name="Theme" parent="android:style/Theme">
</style>

<style name="Theme.Pink">
       <item name="android:background">#ffc0cb</item>
</style>

<style name="Theme.Yellow">
       <item name="android:background">#FFE97E</item>
</style> 

Themes are set in the Activity OnCreate with:

setTheme(R.style.Theme.Yellow);

The Spinner is set up with:

    bowAdapter = new SimpleCursorAdapter(this, R.layout.spinner_style, bowCursor, 
                 new String[] { DBAdapter.KEY_BOW_NAME }, 
                 new int[] { android.R.id.text1 });
    bowAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    bowSelectSpinner.setAdapter(bowAdapter);

spinner_style.xml contains

<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android= "http://schemas.android.com/apk/res/android"
                android:id="@android:id/text1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="@dimen/but_txt_size"
        android:textColor="@android:color/white"
        android:gravity="center" 
        android:ellipsize="marquee" />

How can I stop the spinner picking up the background colour specified in the theme?

I have been chasung this for 2 days now so any hints gratefully rec

Upvotes: 2

Views: 15935

Answers (1)

ferostar
ferostar

Reputation: 7082

Check this answer: Changing background color for items of Spinner. No matter what your theme's background is, you can set your spinner background to override it.

You can do, from code:

yourView.setBackgroundColor(int color)

or, from xml

<Spinner android:id="@+id/spinner"
     ...
     android:background="#YOUR_HEXA_COLOR"/>

Upvotes: 5

Related Questions