getMaxLines () TextViewCompat looks like the right solution for this.
You can also look in SourceCode in TextViewCompat and copy the functions you need.
Code:
int maxLines = TextViewCompat.getMaxLines(yourtextView);
instead:
int maxLines = yourtextView.getMaxLines();
I highly recommend using lib and TextViewCompat support. But just for completeness, there is also a (current) source TextViewCompatDonut getMaxLines :
static int getMaxLines(TextView textView) { if (!sMaxModeFieldFetched) { sMaxModeField = retrieveField("mMaxMode"); sMaxModeFieldFetched = true; } if (sMaxModeField != null && retrieveIntFromField(sMaxModeField, textView) == LINES) { // If the max mode is using lines, we can grab the maximum value if (!sMaximumFieldFetched) { sMaximumField = retrieveField("mMaximum"); sMaximumFieldFetched = true; } if (sMaximumField != null) { return retrieveIntFromField(sMaximumField, textView); } } return -1; }
source share