kandi background
Explore Kits

ExpandableTextView | collapse like the Google Play's app description | Android library

 by   Manabu-GT Java Version: v0.1.3 License: Apache-2.0

 by   Manabu-GT Java Version: v0.1.3 License: Apache-2.0

Download this library from

kandi X-RAY | ExpandableTextView Summary

ExpandableTextView is a Java library typically used in Mobile, Android applications. ExpandableTextView has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub, Maven.
Android's TextView that can expand/collapse like the Google Play's app description
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • ExpandableTextView has a medium active ecosystem.
  • It has 3825 star(s) with 793 fork(s). There are 108 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 40 open issues and 20 have been closed. On average issues are closed in 159 days. There are 4 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of ExpandableTextView is v0.1.3
ExpandableTextView Support
Best in #Android
Average in #Android
ExpandableTextView Support
Best in #Android
Average in #Android

quality kandi Quality

  • ExpandableTextView has 0 bugs and 0 code smells.
ExpandableTextView Quality
Best in #Android
Average in #Android
ExpandableTextView Quality
Best in #Android
Average in #Android

securitySecurity

  • ExpandableTextView has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • ExpandableTextView code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
ExpandableTextView Security
Best in #Android
Average in #Android
ExpandableTextView Security
Best in #Android
Average in #Android

license License

  • ExpandableTextView is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
ExpandableTextView License
Best in #Android
Average in #Android
ExpandableTextView License
Best in #Android
Average in #Android

buildReuse

  • ExpandableTextView releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • ExpandableTextView saves you 247 person hours of effort in developing the same functionality from scratch.
  • It has 600 lines of code, 38 functions and 22 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
ExpandableTextView Reuse
Best in #Android
Average in #Android
ExpandableTextView Reuse
Best in #Android
Average in #Android
Top functions reviewed by kandi - BETA

kandi has reviewed ExpandableTextView and discovered the below as its top functions. This is intended to give you an instant insight into ExpandableTextView implemented functionality, and help decide if they suit your requirements.

  • Called when the view is clicked .
  • Implement measure .
  • Configures the expandIndicator which allows to show the Expandable TextView .
  • Initialize the ExpandableTextView
  • Initializes the view .
  • Gets the view at the given position
  • Override this to handle the menu item selection .
  • Set menu menu menu .
  • Set the tab layout .
  • Return the number of sample strings

ExpandableTextView Key Features

Android's TextView that can expand/collapse like the Google Play's app description

default

copy iconCopydownload iconDownload
API Level 8 (Froyo) and above.

Setup
------
The library is pushed to Maven Central as an AAR,
so you just need to add the followings to your ***build.gradle*** file:

```groovy

dependencies {
    compile 'com.ms-square:expandableTextView:0.1.4'
}

```

Usage
------
Using the library is really simple, just look at the source code of the [provided sample][1].
(Look at the SampleTextListAdapter.java for the use within a ListView)

The important thing to note is that the view Ids for TextView and ImageButton must be set to
"@id/expandable_text" and "@id/expand_collapse" respectively for this library to work.

Also, you can optionally set the following attributes in your layout xml file to customize the behavior
of the ExpandableTextView.

 * `maxCollapsedLines` (defaults to 8)
 The maximum number of text lines allowed to be shown when the TextView gets collapsed

 * `animDuration` (defaults to 300ms)
 Duration of the Animation for the expansion/collapse

 * `animAlphaStart` (defaults to 0.7f)
 Alpha value of the TextView when the animation starts
 (NOTE)
 Set this value to 1 if you want to disable the alpha animation.

 * `expandDrawable`
 Customize a drawable set to ImageButton to expand the TextView

 * `collapseDrawable`
 Customize a drawable set to ImageButton to collapse the TextView

```xml
  <!-- sample xml -->
  <com.ms.square.android.expandabletextview.ExpandableTextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
      android:id="@+id/expand_text_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      expandableTextView:maxCollapsedLines="4"
      expandableTextView:animDuration="200">
      <TextView
          android:id="@id/expandable_text"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:layout_marginRight="10dp"
          android:textSize="16sp"
          android:textColor="#666666" />
      <ImageButton
          android:id="@id/expand_collapse"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="16dp"
          android:layout_gravity="right|bottom"
          android:background="@android:color/transparent"/>
  </com.ms.square.android.expandabletextview.ExpandableTextView>
```

```java
// sample code snippet to set the text content on the ExpandableTextView
ExpandableTextView expTv1 = (ExpandableTextView) rootView.findViewById(R.id.sample1)
                    .findViewById(R.id.expand_text_view);

// IMPORTANT - call setText on the ExpandableTextView to set the text content to display
expTv1.setText(getString(R.string.dummy_text1));
```

License
----------

    Copyright 2014 Manabu Shimobe

    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.

[1]: https://github.com/Manabu-GT/ExpandableTextView/tree/master/sample

Define style to HTML for webView in Android

copy iconCopydownload iconDownload
webView.loadDataWithBaseURL("file:///android_asset", HTML_STRING, "text/html","utf-8",null);

how can i set min height to my containe and after colick on button then wrapcontent height be equal of text height

copy iconCopydownload iconDownload
ShowMore(
          content: '...',
          desiredMaxHeight: 200.0,
          desiredMinHeight: 56.0,
        ),
...
AnimatedContainer(
          duration: const Duration(milliseconds: 700),
          width: double.infinity,
          height: showStatus == ShowStatus.EXPANDED
              ? widget.desiredMaxHeight
              : widget.desiredMinHeight,
          child: Text(
            widget.content,
            softWrap: true,
            overflow: TextOverflow.fade,
          )),
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';

class ShowMore extends StatefulWidget {
  /// The string which will be used by Text widget
  final String content;

  /// The height in pixels of the largest possible size an AnimatedContainer will be
  final double desiredMaxHeight;

  /// The height in pixels of the smallest possible size an AnimatedContainer will be
  final double desiredMinHeight;

  const ShowMore(
      {Key key,
      @required this.content,
      @required this.desiredMaxHeight,
      @required this.desiredMinHeight})
      : assert(content != null),
        assert(desiredMaxHeight != null),
        assert(desiredMinHeight != null),
        super(key: key);

  @override
  ShowMoreState createState() => ShowMoreState();
}

class ShowMoreState extends State<ShowMore> {
  _ontap update;
  ShowStatus showStatus;

  void _update() {
    setState(() {
      showStatus = showStatus == ShowStatus.EXPANDED
          ? ShowStatus.UNEXPANDED
          : ShowStatus.EXPANDED;
    });
  }

  @override
  void initState() {
    super.initState();
    showStatus = ShowStatus.UNEXPANDED;
    update = _update;
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      AnimatedContainer(
          duration: const Duration(milliseconds: 700),
          width: double.infinity,
          height: showStatus == ShowStatus.EXPANDED
              ? widget.desiredMaxHeight
              : widget.desiredMinHeight,
          child: Text(
            widget.content,
            softWrap: true,
            overflow: TextOverflow.fade,
          )),
      Container(
          width: double.infinity,
          height: 56.0,
          child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                showStatus == ShowStatus.EXPANDED
                    ? RaisedButton(
                        onPressed: () {
                          update();
                        },
                        child: Text("COLLAPSE"))
                    : RaisedButton(
                        onPressed: () {
                          update();
                        },
                        child: Text("EXPAND")),
              ])),
    ]);
  }
}

/// Function that is called when updating a widget
typedef void _ontap();

enum ShowStatus {
  UNEXPANDED,
  EXPANDED,
}

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            ShowMore(
              content:
                  'Lorem ipsum dolor sit amet, prima liberavisse cu mei, his elit fabulas ex. Ne justo dicunt referrentur eam. Eum nulla eleifend id, ex vim ferri vitae pericula, qui epicurei interpretaris te. His ei debitis habemus intellegebat, essent assentior incorrupte ne has. Has te inani option, qui eu etiam feugiat epicurei, posidonium dissentias at nam. Ne his malis probatus consequat. Purto neglegentur vim ea, et vim reque quaestio corrumpit, perfecto singulis no his. Homero minimum efficiendi vix no. Vel an adhuc debet constituam, dicant consul percipitur nam ut, pri vide dicam feugait ei. Lorem homero graeci ex nam, labitur virtute mnesarchum in mel.',
              desiredMaxHeight: 200.0,
              desiredMinHeight: 56.0,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
-----------------------
ShowMore(
          content: '...',
          desiredMaxHeight: 200.0,
          desiredMinHeight: 56.0,
        ),
...
AnimatedContainer(
          duration: const Duration(milliseconds: 700),
          width: double.infinity,
          height: showStatus == ShowStatus.EXPANDED
              ? widget.desiredMaxHeight
              : widget.desiredMinHeight,
          child: Text(
            widget.content,
            softWrap: true,
            overflow: TextOverflow.fade,
          )),
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';

class ShowMore extends StatefulWidget {
  /// The string which will be used by Text widget
  final String content;

  /// The height in pixels of the largest possible size an AnimatedContainer will be
  final double desiredMaxHeight;

  /// The height in pixels of the smallest possible size an AnimatedContainer will be
  final double desiredMinHeight;

  const ShowMore(
      {Key key,
      @required this.content,
      @required this.desiredMaxHeight,
      @required this.desiredMinHeight})
      : assert(content != null),
        assert(desiredMaxHeight != null),
        assert(desiredMinHeight != null),
        super(key: key);

  @override
  ShowMoreState createState() => ShowMoreState();
}

class ShowMoreState extends State<ShowMore> {
  _ontap update;
  ShowStatus showStatus;

  void _update() {
    setState(() {
      showStatus = showStatus == ShowStatus.EXPANDED
          ? ShowStatus.UNEXPANDED
          : ShowStatus.EXPANDED;
    });
  }

  @override
  void initState() {
    super.initState();
    showStatus = ShowStatus.UNEXPANDED;
    update = _update;
  }

  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      AnimatedContainer(
          duration: const Duration(milliseconds: 700),
          width: double.infinity,
          height: showStatus == ShowStatus.EXPANDED
              ? widget.desiredMaxHeight
              : widget.desiredMinHeight,
          child: Text(
            widget.content,
            softWrap: true,
            overflow: TextOverflow.fade,
          )),
      Container(
          width: double.infinity,
          height: 56.0,
          child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                showStatus == ShowStatus.EXPANDED
                    ? RaisedButton(
                        onPressed: () {
                          update();
                        },
                        child: Text("COLLAPSE"))
                    : RaisedButton(
                        onPressed: () {
                          update();
                        },
                        child: Text("EXPAND")),
              ])),
    ]);
  }
}

/// Function that is called when updating a widget
typedef void _ontap();

enum ShowStatus {
  UNEXPANDED,
  EXPANDED,
}

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            ShowMore(
              content:
                  'Lorem ipsum dolor sit amet, prima liberavisse cu mei, his elit fabulas ex. Ne justo dicunt referrentur eam. Eum nulla eleifend id, ex vim ferri vitae pericula, qui epicurei interpretaris te. His ei debitis habemus intellegebat, essent assentior incorrupte ne has. Has te inani option, qui eu etiam feugiat epicurei, posidonium dissentias at nam. Ne his malis probatus consequat. Purto neglegentur vim ea, et vim reque quaestio corrumpit, perfecto singulis no his. Homero minimum efficiendi vix no. Vel an adhuc debet constituam, dicant consul percipitur nam ut, pri vide dicam feugait ei. Lorem homero graeci ex nam, labitur virtute mnesarchum in mel.',
              desiredMaxHeight: 200.0,
              desiredMinHeight: 56.0,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

How to expand textView and automatically the next fields will be moved?

copy iconCopydownload iconDownload
 <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="300dp"
            android:text="Description :"
            android:textSize="20sp"
            android:maxLines="3"
            android:autoSizeTextType="uniform"
            android:autoSizeMinTextSize="12sp"
            android:autoSizeMaxTextSize="20sp"/>
description.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                description.setLines(description.getLineCount());
            }
        });
-----------------------
 <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="300dp"
            android:text="Description :"
            android:textSize="20sp"
            android:maxLines="3"
            android:autoSizeTextType="uniform"
            android:autoSizeMinTextSize="12sp"
            android:autoSizeMaxTextSize="20sp"/>
description.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                description.setLines(description.getLineCount());
            }
        });

RecyclerView reusing variables inside custom view

copy iconCopydownload iconDownload
class ExpandableTextView : AppCompatTextView, View.OnClickListener {

    var isCollapsed = true
    ...
override fun onBindViewHolder(viewHolder :YourViewHolder, position:Int) {
    viewHolder.expandleTextView.isCollapsed = true
// Rest of your code
}
-----------------------
class ExpandableTextView : AppCompatTextView, View.OnClickListener {

    var isCollapsed = true
    ...
override fun onBindViewHolder(viewHolder :YourViewHolder, position:Int) {
    viewHolder.expandleTextView.isCollapsed = true
// Rest of your code
}

Community Discussions

Trending Discussions on ExpandableTextView
  • Define style to HTML for webView in Android
  • how can i set min height to my containe and after colick on button then wrapcontent height be equal of text height
  • How to expand textView and automatically the next fields will be moved?
  • RecyclerView reusing variables inside custom view
Trending Discussions on ExpandableTextView

QUESTION

Define style to HTML for webView in Android

Asked 2021-Jan-15 at 13:02

I want to populate webView with HTML by using the following:

String str = "<html>" +
        "<body>" +
        "<style> \n" +
            "h3 {\"font-family:helvetica,arial,sans-serif;font-size:24px;line-height:1.3;\"} \n" +
            "p {\"font-family:helvetica,arial,sans-serif;font-size:12px;line-height:1.3;\"} \n" +
        "</style> \n" +
        "<h3> Open-Source licenses</h3>\n" +
        "<p> A huge thanks from all of us at to the great people behind the great programs listed below.</p>\n" +
        "<ul>\n" +
        "<li>Asynchronous Http Client for Android</li>\n" +
        "<li>Glide</li>\n" +
        "<li>Google Play Service</li>\n" +
        "<li>Gson</li>\n" +
        "<li>Picasso</li>\n" +
        "</ul>\n" +
        "<hr>" +
        "<h3>Asynchronous Http Client for Android</h3>\n" +
        "<p><a href=\"https://github.com/android-async-http/android-async-http\">https://github.com/android-async-http/android-async-http</a></p> \n" +
        "<p>Unless required by applicable law or agreed to in writing, software<br>distributed under the License is distributed on an &quot;AS IS&quot; BASIS,<br>WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br>See the License for the specific language governing permissions and<br>limitations under the License.</p>\n" +
        "</body></html>";

wb_OpenSource.loadDataWithBaseURL( null, str, "text/html", "utf-8", null );

However, it seems like the style does not make any difference.

Any way to make it work instead of adding style to each line?

UPDATE:

As was suggest below, I created a .css file that looks as follows:

#topHeader {
    font-family:helvetica,arial,sans-serif;font-size:24px;line-height:1.3;
}

#regHeader {
    font-family:helvetica,arial,sans-serif;font-size:20px;line-height:1.3;
}

#topText {
    font-family:helvetica,arial,sans-serif;font-size:14px;line-height:1.3;
}

#regText {
    font-family:helvetica,arial,sans-serif;font-size:12px;line-height:1.3;
}

#links {
    font-family:helvetica,arial,sans-serif;font-size:16px;line-height:1.3;
}

And changed my HTML to be:

"<body>" +
"<link rel=\"stylesheet\" href=\"cssStyles.css\"> \n" +
"<h3 id=\"topHeader\"> Open-Source licenses</h3>\n" +
"<p id=\"topText\"> A huge thanks from all of us at to the great people behind the great programs listed below</p>\n" +
"<ul>\n" +
"<li id=\"regText\"> Asynchronous Http Client for Android </li>\n" +
"<li id=\"regText\"> ExpandableTextView Android Arsenal </li>\n" +

and

wb_OpenSource.loadDataWithBaseURL( "file://android_asset/cssStyles.css", str, "text/html", "utf-8", null );

But it doesn't seem to work.

Thank you

ANSWER

Answered 2021-Jan-15 at 11:01

You can create a separate .css file for styling the elements. Place the .css file in the assets folder and include it in your html code.

Now load the HTML in the webview like below:

webView.loadDataWithBaseURL("file:///android_asset", HTML_STRING, "text/html","utf-8",null);

Source https://stackoverflow.com/questions/65734588

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install ExpandableTextView

You can download it from GitHub, Maven.
You can use ExpandableTextView like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the ExpandableTextView component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.