Support
Quality
Security
License
Reuse
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.
Android's TextView that can expand/collapse like the Google Play's app description
default
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
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
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?
<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
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
}
QUESTION
Define style to HTML for webView in Android
Asked 2021-Jan-15 at 13:02I 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 "AS IS" 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:01You 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);
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit