Changing TextView Opacity in Android Changing TextView Opacity in Android android android

Changing TextView Opacity in Android


you can set the alpha like this

int alpha = 0;((TextView)findViewById(R.id.t1)).setTextColor(Color.argb(alpha, 255, 0, 0));

as the alpha you getting from the seekbar that will be set into the text color


This worked for me:

1. Create class 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. Add this instead of using TextView to create a textview in your xml:

...   <!--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. Now you can use this textview in your activity like:

at=(AlphaTextView)findViewById(R.id.at);at.onSetAlpha(255); // To make textview 100% opaqueat.onSetAlpha(0); //To make textview completely transperent


change method to following

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch){    classicText.setAlpha((float)(gameSelector.getProgress())/(float)(seekBar.getMax()));}