https://github.com/Blogcat/Android-ExpandableTextView
An expandable TextView for Android applications
https://github.com/Blogcat/Android-ExpandableTextView
android android-expandabletextview android-oreo expandabletextview textview
Last synced: about 1 year ago
JSON representation
An expandable TextView for Android applications
- Host: GitHub
- URL: https://github.com/Blogcat/Android-ExpandableTextView
- Owner: Blogcat
- License: apache-2.0
- Created: 2016-02-20T15:30:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-05-18T03:20:13.000Z (about 6 years ago)
- Last Synced: 2024-10-31T07:34:04.652Z (over 1 year ago)
- Topics: android, android-expandabletextview, android-oreo, expandabletextview, textview
- Language: Java
- Homepage: http://www.blogc.at
- Size: 2.07 MB
- Stars: 301
- Watchers: 9
- Forks: 73
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Android-ExpandableTextView
==========================
An expandable TextView for Android applications (4.1+).
[  ](https://bintray.com/blogcat/maven/android-expandabletextview/_latestVersion)
Latest Changes
--------------
- Added support for Android O
- Added RecyclerView Demo
Demo
----
This repository also contains a demo project.

Add dependency
--------------
This library is released in Maven Central and jCenter:
```groovy
repositories {
mavenCentral()
}
```
or
```groovy
repositories {
jcenter()
}
```
library dependency
```groovy
dependencies {
compile 'at.blogc:expandabletextview:1.0.5'
}
```
Usage
-----
Using the ExpandableTextView is very easy, it's just a regular TextView with some extra functionality added to it. By defining the android:maxLines attribute, you can set the default number of lines for the TextView collapsed state.
```xml
```
In your Activity or Fragment:
```java
final ExpandableTextView expandableTextView = (ExpandableTextView) this.findViewById(R.id.expandableTextView);
final Button buttonToggle = (Button) this.findViewById(R.id.button_toggle);
// set animation duration via code, but preferable in your layout files by using the animation_duration attribute
expandableTextView.setAnimationDuration(750L);
// set interpolators for both expanding and collapsing animations
expandableTextView.setInterpolator(new OvershootInterpolator());
// or set them separately
expandableTextView.setExpandInterpolator(new OvershootInterpolator());
expandableTextView.setCollapseInterpolator(new OvershootInterpolator());
// toggle the ExpandableTextView
buttonToggle.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
buttonToggle.setText(expandableTextView.isExpanded() ? R.string.expand : R.string.collapse);
expandableTextView.toggle();
}
});
// but, you can also do the checks yourself
buttonToggle.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View v)
{
if (expandableTextView.isExpanded())
{
expandableTextView.collapse();
buttonToggle.setText(R.string.expand);
}
else
{
expandableTextView.expand();
buttonToggle.setText(R.string.collapse);
}
}
});
// listen for expand / collapse events
expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener()
{
@Override
public void onExpand(final ExpandableTextView view)
{
Log.d(TAG, "ExpandableTextView expanded");
}
@Override
public void onCollapse(final ExpandableTextView view)
{
Log.d(TAG, "ExpandableTextView collapsed");
}
});
```
License
=======
Copyright 2016 Cliff Ophalvens (Blogc.at)
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.