12

I have a custom spinner dropdown xml file in /res/layout/:

spinner_view_dropdown.xml:

<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_item_dropdown"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
style="@style/spinner_item_dropdown" />

I'm setting the spinner dropdown via java:

// "Spinner", aka breadcrumbs
    Spinner spin = (Spinner) findViewById(R.id.breadcrumb_dropdown);

    ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.breadcrumb, R.layout.spinner_view);

    adapter.setDropDownViewResource(R.layout.spinner_view_dropdown);

    spin.setAdapter(adapter);
    // /"Spinner"

Unfortunately, a white background still exists on the spinner popup regardless if I set the background to transparent.

How do I fix this?

iamkoa
  • 2,217
  • 6
  • 21
  • 21
  • You have set the background transparent, however the textview is held in a dialog and the dialog has a background color. – Blundell Feb 18 '12 at 18:11

5 Answers5

29

You can override the style for the dropdown, and the dropdown item by using a Theme in your app that inherits from one of the Android themes, then override the

android:dropDownSpinnerStyle, or android:spinnerDropDownItemStyle, and even the android:dropDownListViewStyle attribute of the theme, pointing to your own custom style instead of the Android style that is defined in their theme. I created a fully customized spinner this way, with a transparent button AND dropdown. I even got rid of the dropdown list dividers, and set my own spacing for the dropdown items when I built the tablet app for Fandango (take a look at the sort movies spinner on the main page of the app).

Everything in Android is customizable, you just have to know where to look. ;-)

Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
  • 3
    Can you give a example how to do that what you have suggested? – Junaid Jan 16 '12 at 11:21
  • @Junaid I think you'd be better off with studying the docs: http://developer.android.com/guide/topics/ui/themes.html – Christopher Perry Jan 16 '12 at 19:20
  • 3
    Maaaaaaan! Thanks for that. But little example still will be useful :) – Roman Minenok Mar 25 '12 at 09:51
  • 2
    An example would be amazing mate, I'd literally worship you like a god.. scarifice a baby lamb to you every harvest etc etc – user965369 Nov 19 '12 at 16:52
  • Sorry guys, I don't have an example handy for you. The code belongs to Fandango. Nothing is stopping you from decompiling the apk (http://www.miui-au.com/add-ons/apktool/), and looking at the themes/styles I wrote though. ;) – Christopher Perry Nov 29 '12 at 04:36
26

Try setting on the spinner this:

android:popupBackground="@android:color/transparent"
Deepzz
  • 4,573
  • 1
  • 28
  • 52
キキジキ
  • 1,443
  • 1
  • 25
  • 44
1

The layout you're defining is only used for an entry of your drop-down, not the drop-down itself. So setting the background to transparent won't have any effect on its background. But even if it would, setting the background to transparent would still have no effect, because a TextView (actually I believe any view) has a transparent background by default.

That being said, the right question would be: can you provide a custom layout for an entry's parent view (which is probably a List)? As far as I know, the answer is no, unfortunately.

mxk
  • 43,056
  • 28
  • 105
  • 132
  • Thank you for your response. What's confusing is that Adobe's Photoshop Mobile seems to use a dropdown system tied to its icons used for editing an image. This is the effect I'm trying to duplicate and I assumed it used a spinner. Here's a movie showing this effect in the application: http://blogs.adobe.com/rjacquez/2009/11/adobe_debuts_photoshopcom_mobi.html – iamkoa Dec 17 '09 at 19:41
  • 1
    maybe they use a custom PopupWindow? http://developer.android.com/reference/android/widget/PopupWindow.html – mxk Dec 18 '09 at 09:33
0

Try

android:cacheColorHint="#00000000" 

to get transparency.

I dont know if it works for you but there is a post http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html that explains why the moving parts of a list appear in the background color.

Maybe its the same issue with your spinner.

n3utrino
  • 2,361
  • 3
  • 22
  • 32
0

It's a bug in 1.5 I think, see here

http://www.symsource.com/index.php?view=article&id=418&option=com_content&format=pdf

Run it in a 1.6 emulator or device, does it still stay white?

I actually came here looking for an approach to this, I suspect this may involve manually writing to the canvas or something like that.

Any ideas.

P.S. Accidentally posted when I thought I was logged in, anyone know how to get rid of the anonymous comment? Maybe an admin could fix this?

Paul Maidment
  • 1,024
  • 2
  • 10
  • 14