I am working with android textview. I need print subscript under superscript.
This is my code:
<string name="abc">Text<sup>supertext</sup><sub>subtext</sub></string>
And this is what i get:
Textsuertextsubtext
But i need something like:
Is it possible to do that only in XML without using java?
You could use 2 text views. One with "Text" and next to it a multi line text view with "Supertext...".
However only do that if it's not strings that may ever be translated.
Related
I'm trying to superscript a number in a title in androidplot, like so:
strings file:
<string name="plot_title_3m">stuff per m<sup>3</sup></string>
xml file:
androidPlot.title="#string/plot_title_3m"
but it doesn't superscript at all, the number is normal styling. I've also tried using
<string name="plot_title_3m">stuff per m<sup>3</sup></string>
but no dice, it actually shows the sup tags in the title
also tried this
<string name="plot_title_3m">stuff per m<small><sup>3</sup></small></string>
and actually found out that the 'small' tags don't work either...
You can use HTML tags to achieve this. To be more exact, you need to use Spans on your input text to achieve this look on TextView, but we have a friendly neighborhood helper class that converts some common HTML tags into spans.
E.g.:
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("X<sup>2</sup>"));
I have a long string, with multiple bold words inside the string.
The styling of the non bold sentences are done inside the TextView XML part and this is looking fine.
But i want to make the bold words bigger and thicker.
Is this possible to change this with XML?
for example:
<string name="long_text">This should be a <b>long</b> text with different <b>styling</b></string>
The bold words are supposed to be 1.5 times bigger
Or should i do this in the Java code?
yes you have to do this in java because there is no way to as per your requirement,
you can use TextAppearanceSpan in java code with Spannable
if i am getting you right than try the following..
textview.setText(Html.fromHtml(getResources().getString(R.string.long_text)));
Mark as right if it works for you .
http://docs.fusioncharts.com/charts/contents/Styles/Font.html
I tried this, along with a lot of things but failed to do so.
Here's what I want.
<string name="ss">Bold. Underlined. Italic. Big. Small</string>
I want to format a little bit of the string.
Where it's written bold, I want it to be bold...and same for others.
I tried a lot of tags ...but well nothing worked, and I couldn't find anything on Google or SO.
I know how to do it in a textview, but that's not what I want...
I'm sending some text resource to an activity that shows it...
If I did it with different text views, I'd have to create several of them, a new one for whenever I want bold text, and that's not very elegant.
Is there a way to simple do this in the XML file ? or some other way ?
Try wrapping your marked up text in CDATA tags. For example:
<string name="ss"><![CDATA[<b>Bold.</b> <u>Underlined.</u> <i>Italic.</i> <big>Big.</big> <small>Small</small>]]></string>
And then use Html.fromHtml wherever you're wanting to display it:
Html.fromHtml(getString(R.string.ss))
This problem has been driving me crazy for ages. It's something sooo simple that you just want it to work!!!
Anyway I've found an answer here at http://www.coderzheaven.com/2011/06/19/styling-text-in-android-through-xml/
The key is to load the resource as a CharSequence using getResources().getText(R.string.xxxx) this will retain all the style information and allow you to use inline styling tags.
My mistake was using getString() because when loading your resource getString() will cause the string to lose all its style information.
exemple:
<string name="ss"><font size="15"><b>Parrainage</b></font><u>subscribe</u></string>
b = bold et u = underline .....etc
This is working for me.
<string name="welcome_messages">Hello, %1$s! You have <b>%2$d new messages</b>.</string>
txt.setText(Html.fromHtml(getString(R.string.welcome_messages)));
more details check Official site:
https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithSpannables
in dimens file write:
<dimen name="size_edittext">180dp</dimen>
and in your xml layout or activity call it:
android:#dimen/ size_edittext
I am parsing data from an XML file which has subscript and superscript characters in them which I got from the character map. Like so:
<value column="Back" null="false">H₂</value>
but when I display it on a textview in Android it gives me this 'Hâ,,'
How can I fix this and display it properly in my app?
I found out how
In the XML file the code should be like this :
<value column="Back" null="false">H<sub>2</sub></value>
So that the parced string value is "H<sub>2</sub>"
then in the java code :
TextView textview.setText(Html.fromHtml(YourString);
and for superscript use "sup" instead of "sub"
You can use <small> tag along with <sub> or <sup> tags to decrease the size of the text.
For example:<sup><small>your-string</small></sup>
If you want to still decrease the size of text,you add <small> tag once more like this<sup><small><small>your-string</small></small></sup>
I'm using android studio and it is working perfectly for me !
i found this method useful for me.
strings.xml
<string name="your_string">H<sub>2</sub></string>
You can change it easier than that, just write in #strings or where you want<sub>your-string-here</sub> for subscript or <sup>your-string-here</sup>.
The subscripted letters(of your word) still have the same size as your text. You need to decrease it's size.
For that, use , where number means the size of the text you want.
In my project I need to display the instructions page. The page consists of 8 instructions. So do we need to create 8 textviews to display those instructions? Is it possible to display all those instructions using one single textview?
I read about multi-line textviews.
But for my case can I do so to display all 8 instructions in one textview?
As far as I recall, the newline character \n is recognised when used in strings.xml, so you could declare your instructions there and reference it in the layout. I never found a way to do it within the layout XML itself, but there may be something.
Edit: for clarity - I mean using the escaped character, e.g.:
<string name="instructions">Line 1\nLine 2</string>
You can use \n new line character from string resource or thru code:textView.setText("1st line\n 2nd line");
You can use html to format your string: textView.setText(Html.fromHtml("item 1<br>item 2<br>"));
You can use: StringBuilder to it.