Android: Text formatting in paragraphs - android

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.

Related

How to gives space to paragraph inside string value

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.

Android TextView HTML text break at the end of line

In my text view, I am setting the HTML text:
mTextView.setText(Html.fromHtml("THIS USEFUL INTERESTING HTML TEXT IS DISPLAYED IN ANDROID TEXT VIEW"));
The Text is displayed as below:
The long word at the end is breaking with a hyphen. I want the complete word to go into the next line instead. How can I achieve this? I need to use HTML text only. The text can be dynamic and has to scale across various display size and orientations, I cannot put newline char in the text.
I'd suggest you to use attribute android:ellipsize to prevent breaking up a word
Try this...it should work
mTextView.setText(Html.fromHtml("THIS USEFUL" +"<br/>"+ "INTERESTING HTML TEXT IS DISPLAYED IN ANDROID TEXT VIEW"));
How to have HTML New Line Feature in Android Text View? for more clarity

Character for inserting line break instead of creating paragraph in Android

Is there a character for inserting line break without creating new paragraph in TextView?
Really I have a bidirectional text and want to display it in TextView. Now I have to add line breaks between LTR and RTL parts of text without changing direction of text after each line break.
It is obvious that using \n creates new paragraphs so direction of each new paragraph will be determined by its content and will be not typeset with direction of whole of the text.
In LibreOffice Writer we can use SHIFT+ENTER for adding line breaks instead of new paragraphs. Is this possible in Android? Note I do not want to use <br/> tag of HTML.
you can use \n where you want to break the line as below
textView.setText("Hello \n World")
or
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello \n World"
android:textSize="45dp"/>

I want to write in a different line in textview

My point is i only can write/select 1st line of the textview i want to have for example:
My name is:
12345
Is it even possible to write in 2nd line or more lines?
My name is:\n12345
for more lines use more \n\n\n\n\n :-)
You can also do many thing like....Bold italic or showing in list using one Text view.
Write your text in HTML format. i.e
String youttext="<b>My Name is Avi</b><br><br> <i>I m a Android Developer</i><br><br><ul><li>I m a Blogger too</li></ul>"
Textview yourview=(Textview) findViewById(R.id.textview);
yourview.setText(Html.fromHtml(youttext));
You can show the Text in HTML format too. If you want to change the specific color text and style or shading etc.

EditText space characters to break line?

I have a multiline EditText.
Whenever the input text is reaching its maximum width, the line breaks and the text is moving
to the next line.
However, it isn't working well with spaces.
When there is an input like "blabla" and then lots of spaces, the line not breaks and the text
is being pushed to the left until it "goes out" of the EditText.
How can I treat the spaces as "regular" characters for it to work?
thanks!
my suggestion convert it to html plain text. i mean
edittext.settext(Html.fromhtml(your text));
i hope it will help you...
Do you want to replace all spaces by newline?
String test = "";
test = your_et.getText().toString();
test.replaceAll(" ", "\n");
your_et.setText(test);

Categories

Resources