这为我工作:
<>1>。 创建<>AlphaTextView:
public class AlphaTextView extends TextView {
public AlphaTextView(Context context) {
super(context);
}
public AlphaTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AlphaTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onSetAlpha(int alpha)
{
setTextColor(getTextColors().withAlpha(alpha));
setHintTextColor(getHintTextColors().withAlpha(alpha));
setLinkTextColor(getLinkTextColors().withAlpha(alpha));
getBackground().setAlpha(alpha);
return true;
}
}
<>2>。 添加这段文字,而不是用文字写成文view:
...
<!--use complete path to AlphaTextView in following tag-->
<com.xxx.xxx.xxx.AlphaTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="sample alpha textview"
android:gravity="center"
android:id="@+id/at"
android:textColor="#FFFFFF"
android:background="#88FF88"
/>
...
<>3>。 现在,你可以在你的活动中利用这一案文:
at=(AlphaTextView)findViewById(R.id.at);
at.onSetAlpha(255); // To make textview 100% opaque
at.onSetAlpha(0); //To make textview completely transperent