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.
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 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 .
I am developing an Android app which parses an xml file from a online server and extracts a string from it and stores it in a local variable which is then displayed in a textview. I want some part of the extracted text to be displayed in Bold. How do I achieve that? I can make separate text view for only the Bold part and give it a bold attribute, but then I would have too many views and that would slow down the app.
I have access to the xml file on the server and I can make changes to it if required. Is there any way I could format the text in the xml file itself and then be displayed "as is" in the textview?
Try with
textView.setText(Html.fromHtml(htmlText));
If htmlText is let's say
example <strong>string</strong>
this will work.
When you set the text in the TextView, you can load basic HTML as well, like so:
text.setText(Html.fromHtml("Hello <b>world</b>"));
In that example, "world" would be bolded.
I want to access text of particular line in a multi-line TextView. Any suggestions on how I could do this?
Fetch the Layout (android.text.Layout) of the TextView by calling mTextView.getLayout(); There you can for instance use the getLineStart or getLineEnd methods to get the offset of the text. That combined with getText and used using normal String operations should probably be enough for u!
By default, text view is multi line. Set the text with new line characters for ex. "First line \nSecond line".
Another option is listed here : https://stackoverflow.com/questions/2610280/how-to-get-multi-line-text-on-a-button-in-android
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.