ShowMoreLess is a A simple Android library for displaying a more and less functionality in TextView
Add Jitpack to your project build.gralde file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then add this dependency to your app build.gradle file.
dependencies {
implementation 'https://github.com/noowenz/ShowMoreLess:latest-release'
Or
implementation 'com.github.noowenz:ShowMoreLess:1.0.3'
}
ShowMoreLess.Builder(this)
/*.textLengthAndLengthType(
length = 100,
textLengthType = ShowMoreLess.TYPE_CHARACTER
)*/
.textLengthAndLengthType(
length = 5,
textLengthType = ShowMoreLess.TYPE_LINE
)
.showMoreLabel("show more")
.showLessLabel("show less")
.showMoreLabelColor(R.color.colorPrimaryDark)
.showLessLabelColor(R.color.colorPrimaryDark)
.labelUnderLine(labelUnderLine = false)
.labelBold(labelBold = false)
.expandAnimation(expandAnimation = true)
.enableLinkify(linkify = false)
.textClickable(
textClickableInExpand = true,
textClickableInCollapse = true
)
.build().apply {
addShowMoreLess(textView = tv_first, text = tv_first.text, isContentExpanded = true)
setListener(object : ShowMoreLess.OnShowMoreLessClickedListener {
override fun onShowMoreClicked() {
//We can handle or save show more state
}
override fun onShowLessClicked() {
//We can handle or save show less state
}
}
)
}
.textLengthAndLengthType(
length = 100,//Length where to add show more text
textLengthType = ShowMoreLess.TYPE_CHARACTER //textLengthType is TYPE_CHARACTER
)
and
.textLengthAndLengthType(
length = 5,//Line of text view where to add show more text
textLengthType = ShowMoreLess.TYPE_LINE //textLengthType is TYPE_LINE
)
.showMoreLabel("read more")
.showLessLabel("read less")
.showMoreLabelColor(Color.parseColor("#ffffff"))
.showLessLabelColor(Color.parseColor("#ffffff"))
.labelUnderLine(labelUnderLine = false)//true for underline and false for not underline
.labelBold(labelBold = false)//true for bold and false for normal
.expandAnimation(expandAnimation = true)//expandAnimation will affect both expand and collapse logic
.textClickable(
textClickableInExpand = true,//It will enable text clickable in expand mode
textClickableInCollapse = true//It will enable text clickable in collapse mode
)
8. Can handle enableLinkify() will linkifies WEB_URLS, EMAIL_ADDRESSES, PHONE_NUMBERS and MAP_ADDRESSES
.enableLinkify(linkify = true)//If linkify = true then should disable point no 7.textClickable to work
addShowMoreLess(
textView = tv_first, //It is a text view where we have to add read more or less
text = tv_first.text, //String in textview
isContentExpanded = true//Content expand or collapse history
)
setListener(object : ShowMoreLess.OnShowMoreLessClickedListener {
override fun onShowMoreClicked() {
//We can handle or save show more state
//This sate will send in no 7.addShowMoreLess() function of isContentExpanded = false / true
}
override fun onShowLessClicked() {
//We can handle or save show less state
//This sate will send in no 7.addShowMoreLess() function of isContentExpanded = false / true
}
}
Copyright (c) 2020 Nabin Shrestha
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.