For my app i want to add a FAQ page which contains large amount of text. Some of it has to be bold, underlined. I have an faq_xml with a scrollview. How do i add this large amount of text in a well displayed format? I read some online forums saying about using the html format. I couldn't understand. Some help would be appreciatd!
android:maxLines = "any integer"
android:scrollbars = "vertical"
Then use:
yourTextView.setMovementMethod(new ScrollingMovementMethod());
in your main activity.
You can create a string containing HTML code. This String will then be used in a webView that you will make in you faq_xml.
Check this thread..
You can assign your html code to a string and then apply that css file you learned to create in the above mentioned thread.
Then call the webView like
wv.loadDataWithBaseURL("", YourStringHere, mimeType, encoding, "");
For your ease check out this thread..
Related
I know that I can use the default Html.fromHtml(string) but it highlights links by default. Is there a way to prevent that behavior?
P.S.
I'm trying to feed it straight to TextView using .setText() without saving it to String. I want to keep all the formatting except links.
If you only need text you can fetch it with:
String string = Html.fromHtml(string).toString();
Edit:
Since you want to remove only the links, you can use String.replaceAll before parsing the html:
// Remove <a href*>
html = html.replaceAll("<a href.*?>", "");
// Remove </a>
html = html.replaceAll("</a>", "");
textView.setText(Html.fromHtml(html));
I'm looking for ways to convert text with spaces and symbols in html in android,
For Example:
"Hi this is my text" to "Hi%20this%20is%20my%20text"
Also with symbols...
Anyone knows any easy way to do it?
What I find is to convert html text to plain text.
Thanks in Advance......
What you need is not HTML but URL encoding, use URLEncoder.encode, see http://developer.android.com/reference/java/net/URLEncoder.html
For example, if your write
String s = URLEncoder.encode("Hi this is my text", "UTF-8");
variable s will contain Hi%20this%20is%20my%20text
Use TextUtils.htmlEncode() for this purpose.
My data in db is stored in html format along with image tags in it. So when I am getting the data from database I am removing the html tags and setting it to textview. My problem is even after removing the html tags, there is a small square box displaying in the emulator indicating that there is some image. How can I remove those square box in emulator which is an indication of image in that html data? Help me regarding this...
Thanks in advance
My Code:
textView.setText(Html.fromHtml(htmlString));
You could do a regex replace <img.+?> on htmlString.
textView.setText(Html.fromHtml(htmlString.replaceAll("<img.+?>", "")));
Untested
since images can look like:
<img ...></img>
and
<img... />
This solution will match both cases:
String htmlBody = htmlString.replaceAll("<img.+/(img)*>", "");
textView.setText(Html.fromHtml(htmlBody));
None of the answers are able to remove all possible img tags.
The most appropriate answer would be
String htmlBody = htmlString.replaceAll("(<(/)img>)|(<img.+?>)", "");
It will remove and tags both. And not remove any content between two images.
hi have a look on this example
String temp="<img>helloo</img><b> this is test</b>";
temp= temp.replace("<img>", "");
temp= temp.replace("</img>", "");
textView.setText(Html.fromHtml(temp));
String = " This is SAMPLE"
I want to increase the size of the SAMPLE alone in String to highlight, but need to be in a single string, this is to set in TextView.
Thanks in Advance.
textView.setText(Html.fromHtml("This is <font color='#707070' size='20'>
SAMPLE</font>"));
Try this:
String str = "This is <b>SAMPLE</b>";
yourTextView.setText(Html.fromHtml(str), BufferType.SPANNABLE);
Moreover, you may decorate your string (str) with html tags to alter the looks.
Or to highlight a part of text without using html stuff, read this
Use Html.fromHtml() in setText() of TextView. Supported Html Tags can be found here Html Tags Supported by TextView
I think this is possible if you pass the text as html with your highlighted part enclosed in html <bold> tag.
You have two options:
1, Format your string in HTML and use HTML.from("Your text");
2, Use spannable. A complete guide can find link here
I am fetching few html content from my server for which I am using JSON parsing. But this converts my html content to unicode values.
For Eg: <p>Spend minimum $10 (in a single same-day receipt) at any outlet<\/p> is getting converted to,
;p>Spend minimum $10 (in a single same-day receipt) at any outlet </p>
Now if I try to set this to my WebView it displays with HTML tags itself. If I try to encode the data using TextUtils.encode it displays the text with unicode values.
Can anyone help me with this.
How should I fetch a HTML content and display it in WebView?
I am not getting your question exactly but, If you want to load HTML in web view in you can use
webView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
and if you want to convert < and > like notation you can use Jsoup Library
Guys thanks for your help. But I have solved this issue myself. I have elaborated my way of solving the issue.
What I did is,
1)convert the unicode value to Spanned like this,
Spanned ss=Html.fromHtml(;p>Spend minimum $10 (in a single same-day receipt) at any outlet </p>");
2)Now convert this Spanned to String like this,
String tempString=ss.toString();
3)And now set this to WebView which solved the problem,
webView.loadData(tempString, "text/html","UTF-8");
Actually this isn't JSON encoder converts data to HTML entities but some other layer, before it passed to JSON encoder.
JSON have nothing to do with HTML tags, usually only quotes encoded by parser (Unicode is supported by most parsers).
You probably need to change the way data is returned by server, to omit encoding of HTML tags braces to HTML entities or decoding entities backin your app.
Update:
To decode HTML entities used in HTML tags (and others too) you may use StringEscapeUtils.unescapeHTML()
To show the HTML page inside the Webview why you require the JSON. create web view inside the XML and write below code Inside the Activity you can see the HTML page.
webView = (WebView)findViewById(R.id.webView);
FrameLayout mContentView = (FrameLayout) getWindow().
getDecorView().findViewById(android.R.id.content);
final View zoom = this.webView.getZoomControls();
mContentView.addView(zoom, ZOOM_PARAMS);
zoom.setVisibility(View.GONE);
webView.loadUrl("http://www.google.co.in/");