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..
Android Html.fromHtml function auto converts undesired text into hyperlinks.
Here is my code:
String htmlContent= "corners of nail.It has to";
textViewContent.setTextHtml.fromHtml(htmlContent));
textViewContent.setText(comment.getContent());
In above code Html.fromHtml treats "nails.It" as a link and converts it into hyperlink.
Here is the result of converted string.
One of the solution which I could think is, put space after fullstop.
Is there any good solution?
You can try something like this.
textViewContent.setText( Html.fromHtml("YOUR DESIRED TEXT"));
textViewContent. setMovementMethod(LinkMovementMethod.getInstance());
Hope it helps.
Provide space between dot and second statement
String htmlContent= "corners of nail. It has to";
textViewContent.setTextHtml.fromHtml(htmlContent));
textViewContent.setText(comment.getContent());
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.
I thoroughly searched on SO but didnt get answer of my question.
I want to set a paragraph, I will set it in XML using
The text contains Title and Steps and regular text. I want to make the Title and Steps in bold and rest in normal text.
I can do this by using different 's but how can I do it in the same TextView.
I mean using the same TextView how can I set different attributes for different sentences?
Use a Spannable String
TextView tv = (TextView) findViewById(R.id.tv);
String steps = "Hello Everyone";
String title="Bold Please!";
SpannableString ss1= new SpannableString(title);
ss1.setSpan(new StyleSpan(Typeface.BOLD), 0, ss1.length(), 0);
tv.append(ss1);
tv.append("\n");
tv.append(steps);
For more styling check the link # http://blog.stylingandroid.com/archives/177
in your strings file
<string name="your_text">
<![CDATA[
<p> <b>Title</b> </p>
<p><b><i>Step 1</i></b><p>step1 content content content content content content</p></p>
<p><b><i>Step 2</i></b><p>step2 content content content content content content content</p></p>
]]>
</string>
Then in your activity
TextView tv=(TextView)findViewById(R.id.textView1);
tv.setText(Html.fromHtml(getString(R.string.your_text)));
And output
You can format it like you would in HTML: let's call this custom_text
<b>Your title here</b>
This is the non-bolded stuff.
And then load the text using the Html class:
mTextView.setText(Html.fromHtml(getString(R.string.custom_text)));
That will create a spannable string and set it on the TextView.
please put this string in to res->string.xml
<string name="your_html">
<![CDATA[p><b>This is bold text</b> rementing is simple text
]]>
</string>
Now you can used whenever you have to require this thing.
tv.setText(Html.fromHtml(getString(R.string.your_html)));
It is bestway and work charm.
TextViews support SpannableStrings. You can either make your custom String or format your string in html and then set it with tv.setText(Html.fromHtml(yourString));
kotlin Solution :
For me, the issue was I had a text set in XML through data binding. I had to remove that. then this started taking effect
val spannableStringBuilder = SpannableStringBuilder(headerText)
spannableStringBuilder.setSpan(StyleSpan(Typeface.BOLD), 0, headerText.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
spannableStringBuilder.append(" ")
spannableStringBuilder.append(subText)
textView.text = spannableStringBuilder
The best way to do this is in the Strings resources.
<string name="sample_string"><![CDATA[<b>Title</b>StackOverflow]]></string>
Notice, the text between bold tag (<b> </b>) will appear in bold. Similarly, you can set other styles. For eg. <i> for italics and <u> for underline.
Hope this helps, good luck!
Instead, use this :
First, declare textView
TextView tv1 = (TextView) getActivity().findViewById(R.id.t1);
Then set it's text to the string you want
tv1.setText(Html.fromHtml(getString(R.string.my_text)));
Lastly, use set the typeface for your textView
tv1.setTypeface(null, Typeface.BOLD);
And, you are done.
I have a string which contain three words. I want to show the three words in same textview but in different line. For this I have used <br> tag. Now I want to show the last word in red color. I tried so many codes but nothing worked for me.
My code snippet is
viewHolder.cutomerinfo.setText(
customerDetail[0]+Html.fromHtml("<br>")+
customerDetail[1]+Html.fromHtml("<br>")+
Html.fromHtml("<font color='#ff0000'>")+
customerDetail[2]+Html.fromHtml("</font>"));
Do like that:
code:
String toshowstring = customerDetail[0]+customerDetail[1]+
"<font color='red'>"+customerDetail[2]+"</font>";
viewHolder.cutomerinfo.setText(Html.fromHtml(toshowstring));
That's all you want.
^-^
//only one Html.fromHtml() method is enough
viewHolder.cutomerinfo.setText(
customerDetail[0]+Html.fromHtml("<br>"+customerDetail[1]+
"<br><font color='#ff0000'>"+
customerDetail[2]+"</font>"));
for Ref: