Changing TextView Opacity in Android

Michael Brew picture Michael Brew · Jan 12, 2012 · Viewed 42k times · Source

So I'm trying to dynamically change the opacity of a TextView in my android app. I have a seekbar and as I slide the thumb to the right, the TextView I have layered under it should start becoming transparent. When the thumb reaches about half way across the seekbar, the text should be completely transparent. I'm trying to use the setAlpha(float) method inherited from View on my TextView, but Eclipse is telling me setAlpha() is undefined for the type TextView. Am I calling the method in the wrong way? Or is there another way to change the opacity?

Here's my code (classicText is the TextView, gameSelector is the seekbar):

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

Answer

Pratik picture Pratik · Jan 12, 2012

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