Search code examples
androidspinnertransparentalphainvisible

Android 2.2 - how do i set an spinner's alpha property?


I'm trying to make a spinner totally transparent. In Android 4.0 I can do this setting the alpha property to 0 in the xml layout designer. But when I work with Android 2.2 i can't use that property, Eclipse mark it as an error and tell me that i can't use it.

I tried to make it transparent writting this java code:

final Spinner cmbCategorias = (Spinner) findViewById(R.id.cmbCategorias);
cmbCategorias.getBackground().setAlpha(0);

and it works, but the text in the spinner keeps visible.

Someone can tell me what can i do?? Thanks


Solution

  • Make xml Layout like spinner_textview.xml

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/txtview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textColor="@android:color/transparent" />
    

    And add the following in Java Code:

    Spinner sp=(Spinner)findViewById(R.id.sp);   
      sp.setAdapter(new ArrayAdapter(this,R.layout.spinner_textview, 
                    items));