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

大憨熊 提交于 2019-12-06 11:10:27

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

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.

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