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());
}
View. setAlpha (float xxx); range of xxx - 0 - 255, 0 being transparent and 255 being opaque.
Here is a simple function to change the opacity of a view in android. Opacity is called alpha in android. so setAlpha(int) will do the job. ImageView img = (ImageView)findViewById(R.
I think this is a simple way to set alpha or opacity programmatically for TextView. By using function withAlpha after getTextColors from textView.
// alpha value between 0..255
// 0 for transparent
classicText.setTextColor(classicText.textColors.withAlpha(100))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With