2012-05-08 25 views
2

我試圖讓一個微調器完全透明。在Android 4.0中,我可以在xml佈局設計器中將alpha屬性設置爲0。但是,當我使用Android 2.2時,我無法使用該屬性,Eclipse將其標記爲錯誤,並告訴我我無法使用它。Android 2.2 - 我如何設置微調器的alpha屬性?

我試圖使它透明書面方式,這個Java代碼:

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

和它的作品,但在微調文本保持可見。

有人可以告訴我該怎麼辦? 感謝

回答

2

使XML佈局像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" /> 

並添加Java代碼如下:

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

我做了這樣的功能:

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

它也適用於紡紗人員。