TextView dissipated

3

Hello everyone I have a question how I can make the end of my textView show dissipated or with some transparency for example to my textView I put a text that is long and my textView has a fixed size that I put it and I would like that instead of being cut by my text, at the end I would show myself as dissipated or with some transparency like this

Thank you very much in advance.

    
asked by Gunnar 08.04.2016 в 14:02
source

3 answers

1

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);

    
answered by 08.04.2016 / 19:55
source
1

Making use of alpha and adding the textStyle property to your TextView You have two ways:

XML

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Medium Text"
    android:alpha = ".3"
    android:textStyle="normal|italic"
    android:id="@+id/high_Score"
    android:layout_gravity="center"
    />

PROGRAMMICALLY

textView.setTypeface(null, Typeface.ITALIC); // O Typeface.BOLD_ITALIC si quieres en negrita.

For transparency:

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

    
answered by 08.04.2016 в 17:25
0

If it's just a text, you can use html and, by assigning colors with transparency, do it by hand. For example, this text:

String texto = "<font color=#cc0029>Ahora sin transparencia</font> <font color=#99000000>Ahora con transparencia</font>";

 mTextView.setText(Html.fromHtml(texto));

Anyway, if you do it this way, a gradient to transparent so progressive with that of your image will be tedious. I still put it to you in case it serves you.

    
answered by 08.04.2016 в 14:20