Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing TextView Opacity in Android

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());
}
like image 904
Michael Brew Avatar asked Jan 12 '12 04:01

Michael Brew


People also ask

How do I change the opacity of text on Android?

View. setAlpha (float xxx); range of xxx - 0 - 255, 0 being transparent and 255 being opaque.

How do I change opacity of an image in Android?

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.


1 Answers

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))
like image 56
Bayu Wijaya Permana Putra Avatar answered Nov 11 '22 04:11

Bayu Wijaya Permana Putra