Make your long textview setup easily and quickly
dependencyResolutionManagement {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.eriffanani:TextViewReadMore:4.1.0'
}
- Basic
<com.erif.readmoretextview.TextViewReadMore
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:readMoreMaxLines="3" (Default 1)
android:text="YOUR TEXT HERE"/>
- Expand
<com.erif.readmoretextview.TextViewReadMore
app:readMoreMaxLines="3" (Default 1)
app:expandText="Open Text" (Default "Read More")
app:expandTextColor="@color/teal_200" (Default Color.BLUE)
app:expandTextStyle="bold|italic" (Default normal)
app:expandTextUnderline="true" (Default false)
android:text="YOUR TEXT HERE"/>
- Collapse
<com.erif.readmoretextview.TextViewReadMore
app:collapseText="Close Text" (Default "Close")
app:collapseTextColor="@color/teal_200" (Default Color.BLUE)
app:collapseTextStyle="bold|italic" (Default normal)
app:collapseTextUnderline="true" (Default false)
app:collapsed="false" (Default true)/>
<com.erif.readmoretextview.TextViewReadMore
app:duration="200"
app:interpolator=""
app:interpolatorExpand="bounce"
app:durationExpand="800"
app:interpolatorCollapse="anticipate_overshoot"
app:durationCollapse="900"/>
<!--Animation Interpolator-->
<flag name="decelerate"/>
<flag name="accelerate"/>
<flag name="anticipate_overshoot"/>
<flag name="anticipate"/>
<flag name="bounce"/>
<flag name="fast_out_linear_in"/>
<flag name="fast_out_slow_in"/>
<flag name="linear_out_slow_in"/>
<com.erif.readmoretextview.TextViewReadMore
app:ellipsisType="none" (Default dots)/>
<com.erif.readmoretextview.TextViewReadMore
app:actionClickColor="@color/colorRed" (Default @color/text_view_read_more_button_hover_color)/>
TextViewReadMore txtReadMore = findViewById(R.id.txtReadMore);
txtReadMore.onClickExpand(v -> txtReadMore.toggle());
txtReadMore.onClickCollapse(v -> txtReadMore.toggle());
- Java
txtReadMore.toggleListener(collapsed -> { // TODO ACTION });
- Kotlin
txtReadMore.toggleListener { collapsed -> // TODO ACTION }
![](https://private-user-images.githubusercontent.com/26743731/255962970-aaee9b13-b095-4f3e-95f4-6319c3e2dbc9.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1OTE0NjQsIm5iZiI6MTcyNTU5MTE2NCwicGF0aCI6Ii8yNjc0MzczMS8yNTU5NjI5NzAtYWFlZTliMTMtYjA5NS00ZjNlLTk1ZjQtNjMxOWMzZTJkYmM5LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA2VDAyNTI0NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA1M2YxMTgzZjk0ZGNiNDJlYzU5NjgwZjA4MDBmMGZjNWYwNzE0MDVhMzQ0NTdjZTVhODE2MDJmOGM0YWVmNjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.uu1U-2cD04kEHIkjf2UYOTmSlHVzg83Vczegh9w7zh8)
- Use collapse function to onBindViewHolder
/**
item.isCollapsed() is variable from your item to store and save state of
textview (collapsed/expanded) when item displayed again from RecyclerView scroll
*/
holder.text.collapsed(item.isCollapsed());
- Use Toggle
holder.text.onClickExpand(v -> holder.text.toggle());
holder.text.onClickCollapse(v -> holder.text.toggle());
holder.text.toggleListener(collapsed -> {
item.setCollapsed(collapsed);
notifyItemChanged(position);
});
- Use Collapse Properties
// onClickExpand or onClickCollapse
holder.text.onClickExpand(v -> {
boolean status = !item.isCollapsed();
holder.text.collapsed(status);
item.setCollapsed(status);
notifyItemChanged(position);
});
![](https://private-user-images.githubusercontent.com/26743731/255963428-9315357b-6974-4796-a4db-df2d5bd56d74.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1OTE0NjQsIm5iZiI6MTcyNTU5MTE2NCwicGF0aCI6Ii8yNjc0MzczMS8yNTU5NjM0MjgtOTMxNTM1N2ItNjk3NC00Nzk2LWE0ZGItZGYyZDViZDU2ZDc0LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA2VDAyNTI0NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTUxMTNmN2E2MTk5NDhiZjkyNDBkNmEyNThhZDU1YjQ2YTFjZWI0ZDcyNTViNmY2ZmVhNjE0ZjNmMGJjMWY1OTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.0TfSUUKB8C4niuJyd8Zn-HJU66M5gzWQ3HvN76SbmCY)
This library is still being developed further, please provide feedback if you find a bug. Thank you
Copyright 2022 Mukhammad Erif Fanani
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.