Home » Android » How to fade edge of TextView in Android?

How to fade edge of TextView in Android?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am working on Android 3.0.
I have a TextView on my layout and I want it to be faded after 8 characters like in the main menu. This Text is located in RelativeLayout.

<TextView android:layout_width="wrap_content"   
android:layout_height="wrap_content"        
android:id="@+id/item_name"         
android:textStyle="bold"        
android:textColor="@color/white"        
android:maxWidth="50dp"         
android:maxLength="8"       
android:layout_below="@+id/item_frame"  
android:layout_alignBottom="@+id/item_view"         
android:layout_centerHorizontal="true" 
android:fadingEdge="horizontal"> 
</TextView>

Does anyone has an idea how to fade the text after few characters?

How to&Answers:

I think you need to combine fadingEdge with ellipsize and singleLine, and even then it will only happen if the text is longer than the control’s width.