I have a TextView
which firstly shows a small portion of a long text.
The user can press a \"see more\" button to expand the TextView
and s
Cliffus' answer came close to what I was looking for, but it doesn't support using the setMaxLines()
method, which causes issues when you can't set the max lines through XML.
I've forked their library and made it so that using setMaxLines()
won't break the expand/collapse action. I also updated the Gradle configuration and migrated it to AndroidX. Otherwise, the usage is the same as before.
You can include it in your project using Jitpack:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.zacharee:Android-ExpandableTextView:Tag'
}
Where Tag
is the latest commit tag (https://jitpack.io/#zacharee/Android-ExpandableTextView/).
The usage is exactly the same as the original library's. Include the ExpandableTextView in your XML:
And expand/collapse in code:
if (expandable.isExpanded) {
expandable.collapse()
else {
expandable.expand()
}