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

删除回忆录丶 提交于 2019-12-10 10:54:20

问题


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


回答1:


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



回答2:


I did a function like this:

private void enableView(View v, boolean enable)
{
    if(v.isEnabled() == enable)
        return;

    float from = enable ? .5f : 1.0f;
    float to = enable ? 1.0f : .5f;

    AlphaAnimation a = new AlphaAnimation(from, to);

    a.setDuration(500);
    a.setFillAfter(true);

    v.setEnabled(enable);
    v.startAnimation(a);
}

It works for spinners too.



来源:https://stackoverflow.com/questions/10495084/android-2-2-how-do-i-set-an-spinners-alpha-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!