I want to Justify the text into textView. I does not want to use web view. because i can't increase the text size at run time for different screens. So I want To use the text view.
I want some things like that.
You can set HTML on a TextView.
So...
String htmlString = "<p align=\"justify\">This is some text in a paragraph.</p>";
mTextView.setText(Html.fromHtml(htmlString));
Good Luck. :)
Related
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
I want to add second textview, just after completion of the first one. Linear layout with orientation horizontal didn't help.
Any other alternatives? Please suggest!
Generally, we use HTML text for this information.
We can use as many text styles as we want for different texts. With this way, you can set properties for each texts differently.
For Example: <HTML><text1><text2></HTML>
In the above, you can define text properties independently. Finally place this text in Textview. So we can achieve this using single TextView itself.
Example:
String str = "<a>This is a <font color='#800000FF'> blue text</font> and this is a <font color='red'> red text</font> </a>";
TextView textView = (TextView)findViewById(R.id.text);
textView.setText(Html.fromHtml(str, Html.FROM_HTML_MODE_COMPACT));
I would like to display some text in a TextView, but I would like to avoid text wrapping in a specific position of the text, to avoid the text to display like this:
This is my very long text
:
Instead, I want my text to display as following:
This is my very long
text :
You may ask: why is there a space before :?
Simply because it's in French, and, unlike English, you're supposed to add an extra space before this character (also available with ? and !).
I tried this:
TextView myTextView = (TextView) findViewById(R.id.my_text);
myTextView.setText(Html.fromHtml("This is my very long <span style=\"white-space: nowrap;\">text :</span>"));
But of course, it doesn't work.
I was also thinking of a specific character that behaves like a space but without wrapping. I don't know if it exists, and if it's a good practice.
I finally found out a solution for the specific white space wrapping problem: just add \u202F instead of your white space in your string, like for example:
<string name="my_string">This is my very long text\u202F:</string>
In my application, I have an TextView with many lines beside of product, but I need the data with proper appearance.Is it possible to have justified alignment dynamically?
you can align your text dynamically some how as you want...
but, i guess there is no such facility available in android to fully justify text as the text editors does...
Use Html Formatting in your textView like
yourTextView.setText(Html.fromHtml("<h1>Product Name</h1><br><p>Content</p>"));
Yes you can get the instance of TextView on activity startup
TextView t = (TextView)FindViewById(R.id.TextView1)
t.setTextAppearance(context,parameter)
Is it possible to have a black background around each letter (not for the whole word) in a word in a TextView?
The only way I can think of is by using html in your textView.
Put your text in HTML and then do something like this
TextView contactWeb1 = (TextView) findViewById(R.id.contactWeb1);
String desc = "<font color=\"red\"><a href='http://www.mysite.com/'>Visit my site</a></font>";
contactWeb1.setText(Html.fromHtml(desc));
The above code is from the 3rd link
Here are some related questions
Is it possible to have multiple styles inside a TextView?
How to display HTML in TextView?
Android Linkify links textColor ignored, css style overrides possible?