I have some text inside string of value folder in android studio and I want to give space between paragraph but I don't know how to do that ?
you can use \n for new line and add space by entering space
for example:
<string name="above_eightteen">I confirm that \n I am above 18 years and agree to all Age restriction disclaimer.</string>
and use this string value in your layout.
Most probably your text will be a straight line in the string.xml file. find out the point where a paragraph is starting or ending, and put "\n" before paragraph start or after paragraph end.
Related
Is there a way to create/override the custom word wrap engine for Android TextView?
For example,
My name is Edwin (US:1113)
Should be displayed as
My name is Edwin
(US:1113)
Instead of
My name is Edwin (US:
1113)
Already tried changing all the possible value for the setting below but nothing good.
Android:maxLines
Android:setHorizontallyScrolling
Android:ellipsize
Android:singleLine
In my findings, word wrap in TextView does not include special characters such as :.
Updated 3.09AM 2/7/2018 UTC
As mentioned by #Umair, line breaking with "\n" is not possible because I don't know the length of the text before the colon :. This will line break the sentence too early before it reached the maximum width of the TextView.
Use 2 TextViews inside a LinearLayout with horizontal orientation and put My name is Edwin in the 1st and (US:1113) in the 2nd. If there is no space for the 2nd TextView then it will fall to the next line.
I have text which is in xml and its a long text divided into several paragraphs. How shall I store this text in db and then retrieve it so that I get the text in the paragraphs form?
"Heading\n\n\tThis is the first paragraph and you can see the second paragraph below.\n\n\tThis is the second"
Store like this. Use \n\n\t before starting each paragraph. \n is for new line and \t for tab.
I want to display help dialog box in which it has one textview and it loads the content from the String.xml file. Instead of making it one boring paragraphs, I would like to add some formatting to that String.xml For example coloring some sentences, bold..etc. Is there a way I can do that in the xml file within the string?
My xml looks like that
<string name="help_summary">Clicking on button (Summary) will result in ((report))</string>
So I want (Summary) to be red color and ((report)) to be bold.
How can I achieve that?
You can use Html. When you load the string in the textview use:
yourTextView.setText(Html.fromHtml(context.getResources().getString(R.string.help_summary)));
And use html in the string, for example:
<string name="help_summary"><![CDATA[Clicking on button <span style="color:red">Summary</span> will result in <b>report</b>]]></string>
There are some attributes that can be used in string resources without implementing HTML into and or altering your java code. None needed, you CAN do most of what you seem to need in strings.xml
Example:
<string name ="my_string"><i>italics</i><b>bold</b><u>underline</u><font fgcolor="#FFFFFFFF">color</font><small>small text</small></string>
I believe there is a <large/> or <big/> tag as well, amongst a few more.
Edit also, there is \n for a new line. Just include that in your string like so:
<string name="paragraph">Text is one first line \n now text is on next line. \n\n this will appear as an indented paragraph now.</string>
Hope this helps, happy coding!
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.
I have 5-10 lines of address information that I want to insert in a layout in my Android app.
I rather not use seperate textviews, but want to have one where I can insert line breaks manually.
I do this by adding \n and it seems to work, BUT.. This also adds padding or a space, I'm not sure which one.
Example:
This XML
<string name="contact_address">
Street address\n
City\n
Country
</string>
Gives this output:
Street address
City
Country
Anyone know what could be wrong, or do I have to give up and make 5-10 seperate textviews?
Try:
<string name="contact_address">Street address\nCity\nCountry</string>
to get rid of the spaces you are putting into your XML.
I stumbled upon this and figured out a better way to keep the XML formatting and the line breaks without additional padding.
Use
<string>Line 1
\nLine 2
\nLine 3
</string>
Instead of
<string>Line 1\n
Line 2\n
Line 3
</string>