I am writing an view where I need to display superscript data. I am following this to achieve this.
Along this is there any way to change font size(in number) of superscript text.
EDIT
Commanware suggested link work great, except one thing. I need superscript bit above of base text. I'm updating image for same, please refer. I'm using same code with mention in reference code.
Here either can go for separate text view could be second priority solution. Any suggestion !
try this one this is working code:
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("04:30<sup><small>pm</small></sup>"));
you cant pass text size in numbers, yo have to change the size to string :
<font size="3" color="red">This is some text!</font>
Use this Code :
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("your Text <sup style="font-size:5(yourfontsize);">subscript</sup>"));
Try this and Let me know :)
Related
I have a simple TextView, where I put a string like that: "Curăță corect urechile copilașului tău!". But I see the string on display like this "Cură ă corect urechile copilașului tău!" - just space between chars, where must be a "ț" symbol.
I checked the string in TextView by TextView.getText(), and I get my original string.
This is a screenshot, also the same problem in first title:
Try to set text in TextView using HTML. I hope this will work and may help you out.
myTextView.setText(Html.fromHtml("your_string"));
There is still space for the letters, so perhaps it's an issue with the styling.
Change the style to default, do the letters show up?
Try adding a shadow to the textviews and see if the shadow exists (maybe the letters are somehow transparent, or the same color as the background?)
It is more related to a font issue, default Android font doesn't support some characters. You need to try from a different font.
You can try from the following (but I think its not free)
http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=FontDownloads
What I would like to achieve is an effect that looks like this with a TextView:
Basically having a background, but keeping the space between the lines. The only solution I came up with was using one TextView for each line of text, but I would prefer a cleaner one using only one multiline TextView.
Any ideas?
Use spanned text for each line. Read the Spannable API.
please refer to this answer here as it describes how to implement spacing between multiple lines in a TextView , using the following properties :
android:lineSpacingMultiplier
android:lineSpacingExtra
Hope that Helps .
Regards
What you can do is use mark tag in html to textview.
myTextView.setText(Html.fromHtml("<mark>heading highlighted</mark>"));
i have a layout containing multiple TextViews containing text with superscript... to make a portion superscript in text i have used <sup>superscript text</sup> tag in string.xml within text the problem here is my text got cutted in emulator view i have also tried to add padding but output is same nthing is working for it like , changing margin,padding,font size...please help here below is image what i get on emulator........
Make it like this.
< sup>< small>superscript text< /small>< /sup>
A further problem remains: the superscripted text is not properly scaled, i.e. font size reduced.
So padding is just a weak solution to a bug in the proper rendering of a [super|sub]script.
I am investigating a fix for this...will see.
if you want small superscript text than you can use
<sup>< small>text< /small>< /sup>
if you want to more small than you can use <small> tag twice like below
<sup><small><small>text</small></small>< /sup>
I am trying to add lines with different colors to my TextView using html tags.
For whatever reason,
Html.fromHtml("<font color='#145A14'>text</font>");
won't show up colored in the TextView.
Html.fromHtml("<font color='#145A14'>text</font>");
Instead of above please use following
Html.fromHtml("<![CDATA[<font color='#145A14'>text</font>]]>");
This worked for me and I am sure it will also work for you.
Let me know in case of any issue.
My answer involves guesswork about your code, but here goes:
When you use the font tag: DO NOT include an alpha channel so that your hex string looks like "#ff123456". If you use Integer.toHexString(), you will have an alpha channel in that result.
It worked when i used substring(2) on my hex string from rescource.
To sum up:
text.setText(Html.fromHtml("<font color='#123456'>text</font>"));
will work, but:
text.setText(Html.fromHtml("<font color='#ff123456'>text</font>"));
won't!
Make sure to turn off any modifiers like:
android:textAllCaps="true"
The fromHtml method is extremely limited in terms of the HTML tags that it supports, and font is not one of them. See http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html for an unofficial list. I did some research on this myself, and I found that fromHtml is based on an obscure and poorly documented rendering engine.
I use this code
Html.fromHtml(convertToHtml("<font color='#145A14'>text</font>"));
public String convertToHtml(String htmlString) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<![CDATA[");
stringBuilder.append(htmlString);
stringBuilder.append("]]>");
return stringBuilder.toString();
}
That looks like a very dark color, are you sure that your screen is capable to display such colors, so you can distinguish them from black? The code snippet looks good, I've tried similar code many times and it worked like a charm. Try it with somewhat brighter, i.e. #ff0000 (red), to verify that it works:
TextView text = ... // find or instantinate your text view.
text.setText(Html.fromHtml("<font color='#ff0000'>text</font>"));
textView.setText(Html.fromHtml("<font color='blue'>text</font>"));
txt_description1.setText(Html.fromHtml("<font color='rgb'>"+str_description1+"</font>"));
If you do not want a single static color and want to directly reflect from editor you can use "rgb". It will reflect the exact color what you have set in editor, just set in textview and concat it with textview value.
And you are all set to go.
Make sure your RGB value is CAPITALIZED. Android can understand #00FF00 but not #00ff00.
try this and it should works
textView.setText(Html.fromHtml("<font color=\"#145A14\">text</font>"));
Yeah I agree, it doesn't work sometimes.
As an alternative, I use in xml for Textview:
android:textColorLink="yourColor"
works like a charm ;)
For color text with hyperlink URL:
textView.setText(Html.fromHtml("You agree to our <font color='#F20000'><a href='https://www.yoururl.com'> Terms of Service</a></font> and <font color='#F20000'><a href='https://www.yoururl.com'>Privacy Policy</a></font>", Html.FROM_HTML_MODE_LEGACY), TextView.BufferType.SPANNABLE);
This worked for me and I am sure it will also work for all.
I have a textview which should render its content with HTML formatting. From code, this can be achieved like this,
textView.setText(Html.fromHtml(someText));
Is there a way to do this through the XML?
I ask because i do not want to set the text through the code, In my case, the text comes from a DB call and displayed through an adapter.
Yes there are a bunch of (simple) tags that are understood by TextView -- if the text is set in XML from a string resource.
So basically
<TextView text="#string/foo" .. />
It is also possible to give templates like "Hello <b>%s</b>", but here you still need to run some code to fill in the value for %s
Have a look at http://developer.android.com/guide/topics/resources/string-resource.html for formatting hints and short examples.