There are several ways the most common is to apply transparency to the color of the text:
TextView miTextView= (TextView)findViewById(R.id.miTextView);
int myAlpha = 0; // 0 Transparente , 255 completamente opaco.
miTextView.setTextColor(Color.argb(myAlpha, 0, 255, 0)); //Texto color verde.
You can also directly apply the android:alpha
property to the widget:
<TextView
android:id="@+id/miTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hola StackOverflow.com"
android:alpha = ".50"/>
If we define an alpha of 0 the text looks completely transparent, if we define an alpha of 100:
and if we define an alpha of 255, it would look completely opaque.
If you want to apply transparency to part of the text, you can do it with a SpannableString:
TextView myTextView = (TextView) findViewById(R.id.myTextView);
SpannableStringBuilder spannablecontent = new SpannableStringBuilder("Hola StackOverflow!");
int myAlpha = 10; // 0 Transparente , 255 completamente opaco.
ForegroundColorSpan fcs = new ForegroundColorSpan(Color.argb(myAlpha, 0, 0, 0)); // Color del texto Negro con alpha de 10 %
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD);
// Aplica el color definido, texto Negro con alpha de 10 %, a los primeros 4 caracteres.
spannablecontent.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
spannablecontent.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
myTextView.setText(spannablecontent);