Is there a way to check whether a TextView's text is truncated in my code?
You can use method: getEllipsisCount
public static boolean isTextTruncated( String text, TextView textView )
{
if ( textView != null && text != null )
{
Layout layout = textView.getLayout();
if ( layout != null )
{
int lines = layout.getLineCount();
if ( lines > 0 )
{
int ellipsisCount = layout.getEllipsisCount( lines - 1 );
if ( ellipsisCount > 0 )
{
return true;
}
}
}
}
return false;
}
I found the answer at the following related post:
Check if textview is ellipsized in android
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