Light-weighted, convenient implementation of expandable text view that supports expanding & collapsing animations for Android projects

Overview

ExpandableTextView

Light-weighted, convenient implementation of expandable text view that supports expanding & collapsing animations for Android projects.

Why ExpandableTextView?

When the text is too long, a designer reasonably asks if it is possible to truncate the text by having a certain line count limitation. In addition, an expanding call-to-action (ie. "Read more") should be shown at the end of the text. When user taps the text, it expands to show the full content. ExpandableTextView helps creating such behaviour easily.

Demonstration

Normal RTL With drawable
normal.mp4
rtl.mp4
drawable.mp4
maxLines when expand Width changes at runtime
maxLines.mp4
width.mp4

Install

Step 1. Add the JitPack repository to your build file

  • AGP older than 7.1.0
// build.gradle (root level)
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • AGP 7.1.0 and newer
// settings.gradle
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

// build.gradle (module level)
dependencies {
    implementation 'com.github.giangpham96:ExpandableTextView:1.0.1'
}

Usage

Example XML

">
    <io.github.giangpham96.expandabletextview.ExpandableTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/purple_100"
        android:padding="16dp"
        android:maxLines="10"
        app:expandCta="More"
        app:collapsedMaxLines="2"
        app:expandCtaColor="@color/blue_500"
        app:expandableText="@string/long_text" />

Attributes

Attributes Type Description Default value
app:collapsedMaxLines Int The maximum line counts when the text is collapsed 3
app:expandCta String The Cta at the end of truncated text such as "View more" "" (Nothing will be shown at the end of truncated text)
app:expandCtaColor Color The color of expand Cta #ffaa66cc
app:expandableText String The text to be displayed on this text view ""

Public functions

  • collapsedMaxLines public getter & setter for the maximum line counts when the text is collapsed.
  • expandCta public getter & setter for the Cta at the end of truncated text such as "View more".
  • expandCtaColor public getter & setter for the color of expand Cta.
  • expandableText public getter & setter for the text to be displayed on this text view.
  • collapsed public getter to determine if the text is being collapsed
  • expanded public getter to determine if the text is being expanded
  • toggle function that makes the text changes its state from collapsed to expanded & vice versa. It also adds animation transition during the state change.

Notes

  • DO NOT directly use android:text or setText in this view. Use app:expandableText or expandableText instead. Attempting to use android:text or setText will lead to unexpected behaviour.
  • At any time, collapsedMaxLines MUST always be less than or equal to maxLines. Otherwise, an exception will be thrown.
  • This view only supports TextUtils.TruncateAt.END.
You might also like...
[DISCONTINUED] Rrich text editor for android platform. 安卓富文本编辑器,暂停维护

icarus-android Maybe the best rich text editor on android platform. Base on Simditor Features Alignment (left/center/right) Bold Blockquote Code Horiz

Android library contain custom realisation of EditText component for masking and formatting input text
Android library contain custom realisation of EditText component for masking and formatting input text

Masked-Edittext Masked-Edittext android library EditText widget wrapper add masking and formatting input text functionality. Install Maven dependency

An address-autocompleting text field for Android
An address-autocompleting text field for Android

android-PlacesAutocompleteTextView An AutocompleteTextView that interacts with the Google Maps Places API to provide location results and caches selec

Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android
Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android

Chips EditText Library Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I deve

AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size.
AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size.

AutoscaleEditText AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size. Latest Version How to use

Add text masking functionality to Android EditText. It will prevent user from inserting not allowed signs, and format input as well.
Add text masking functionality to Android EditText. It will prevent user from inserting not allowed signs, and format input as well.

MaskFormatter MaskFormatter adds mask functionality to your EditText. It will prevent user from inserting not allowed signs, and format input as well.

Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText
Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText

Simple Linkable Text Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText Installation Gradle Add dependenc

Markdown Text for Android Jetpack Compose 📋.

Markdown Text for Android Jetpack Compose 📋.

Dealing with Android Text by simple way to get high performance.
Dealing with Android Text by simple way to get high performance.

Gapo Android RichText RichText supports Hashtag, Mention, Url, Phone Number, Email, Markdown, Custom Span, SeeMore/SeeLess by limited line or length,

Comments
  • Add support for Api 22 and lower devices.

    Add support for Api 22 and lower devices.

    We must change getStaticLayout function for api 22 and lower devices. I tried adding new StaticLayout constuructor but it doesn't work properly.

    ` private fun getStaticLayout(targetMaxLines: Int, text: CharSequence, textWidth: Int): StaticLayout { val maximumLineWidth = textWidth.coerceAtLeast(0) val alignment = ALIGN_NORMAL val includePadding = true

        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            StaticLayout.Builder
                .obtain(text, 0, text.length, paint, maximumLineWidth)
                .setIncludePad(false)
                .setMaxLines(targetMaxLines)
                .setAlignment(alignment)
                .setEllipsize(END)
                .setLineSpacing(lineSpacingExtra, lineSpacingMultiplier)
                .build()
        } else {
            StaticLayout(
                text,
                0,
                text.length,
                paint,
                maximumLineWidth,
                alignment,
                lineSpacingMultiplier,
                lineSpacingExtra,
                includePadding,
                END,
                width
            )
        }
    }`
    
    opened by egeysn 1
  • Add sdk support for lower devices.

    Add sdk support for lower devices.

    I added sdk support for api 22 and lower devices.

    I faced issue with Static Layout constructor because it is deprecated constructor not support for max lines parameter. It have a constructor but not accessing . I fix this issue it StaticLayoutProxy class from facebook TextLayoutBuilder library.

    Screen Shot 2022-12-18 at 21 31 40
    opened by egeysn 0
Releases(2.0.0)
Owner
Giang H. Pham
Giang H. Pham
Customized and Expandable TextView

Customized and Expandable TextView Simple library to change the Textview as rectangle, circle and square shapes by adding one line of code in xml file

Raja Gopal 62 Sep 22, 2022
Android Custom View for prevent the view behind on-screen keyboard when edit text is focused

Group Focusable Prevent the view behind on-screen keyboard when edit text is focused in Android UI Download Gradle implementation 'com.akexorcist:grou

Akexorcist 8 Jun 22, 2022
Custom view to expand long text with view more,less action , you can customize min lines , action color

ExpandableTextView Custom expadable text view Examples : <mostafa.projects.expandabletextview.ExpandableTextView android:layout_wi

Mostafa Gad 8 Jan 25, 2022
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use <com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

goka 270 Nov 11, 2022
A module designed to encapsulate the use of an Android EditText field for gathering currency information from a user. Supports all ISO-3166 compliant locales/currencies.

CurrencyEditText CurrencyEditText is an extension of Android's EditText view object. It is a module designed to provide ease-of-use when using an Edit

Josh Kitchens 335 Dec 25, 2022
AutoLinkTextView is TextView that supports Hashtags (#), Mentions (@) , URLs (http://), Phone and Email automatically detecting and ability to handle clicks.

AutoLinkTextView Deprecated Please use the new version of AutoLinkTextView AutoLinkTextView is TextView that supports Hashtags (#), Mentions (@) , URL

Arman 1.1k Nov 23, 2022
RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android. Looking for iOS? Check out cjwirth/RichEditorView Supported Functions Bold

Daichi Furiya 6k Jan 2, 2023
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

Feras Alnatsheh 1k Dec 20, 2022
:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

LIBRARY IS NO LONGER MAINTAINED If you want to adopt + maintain this library, please drop me a message - [email protected] Android Full Justific

Mathew Kurian 1.9k Dec 29, 2022
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.

Android Form EditText Android form edit text is an extension of EditText that brings data validation facilities to the edittext. Example App I built a

Andrea 1.5k Dec 14, 2022