这为我工作搜索条获取阿尔法阿尔法:
1.创建类AlphaTextView.class:
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.添加这个,而不是使用TextView的在你的XML创建一个TextView:
...
<!--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.现在你可以使用这个TextView的在你的活动,如:
at=(AlphaTextView)findViewById(R.id.at);
at.onSetAlpha(255); // To make textview 100% opaque
at.onSetAlpha(0); //To make textview completely transperent
这不工作AFAIK。我已经尝试过了.TextView没有名为setAlpha()的方法,请在回答前检查它! – Hiral 2012-01-12 05:24:41
检查方法http://developer.android.com/reference/android/view/View.html#setAlpha(float) – jeet 2012-01-12 05:31:51
这是正确的参考,但你不能在你的eclipse中直接使用这种方法来浏览或查看你的eclipse请检查自己。相反,您需要自定义textview,然后在您的应用中使用该类。 – Hiral 2012-01-12 05:52:50