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?
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 make something like
wow its cool app
in android. so that users can see a bold text in both TextView and EditText like WhatsApp. I don't know what to do. I searched and found something in which we can use HTML tags but some of the users don't know how to use that. Is there a way so that it is easy for users to make some part of text bold and remaining will normal.
Here is the image which will clear more
in this image, users can bold some part of text by enclosing that in *'s.
For you to make text bold? Place it in a StyleSpan with a bold style to it. For the user to make it bold? You'll have to provide some UI for them to do that, that isn't built in.
You have to use HTML code and set to textview or edittextview as following..
TextView textView = (TextView) findViewById(R.id.textView);
String first = "Hello what's up ";
String next = "<B>some bold text </B>";
textView.setText(Html.fromHtml(first + next));
if you want to add bold text after '' character then find that character from textview or edittextview and apply tag after '' this character and set text into textview and edittextview
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.
This may be a ridiculous question ever, but still I want to reduce my effort of creating a lot of text views.
I have text view that contains Name:Value format [Suppose Name:Android] In this case all the attributes for the text view will be same except the color and also the texts are side by side.
In real implementation I have to create two text views, and suppose if I have around 10-15 such pairs, the number of text views will be 20-30 respectively.
So how can I set different color for name and value independently??
Use something like
String str = "<font color=#900000 >Name:</font> <font color=#0000FF>Android</font>";
textview.setText(Html.fromHtml(str));
You can set the text to use html tags to set colors inside the text
String formattedText = "<font color=\"#ff0000\">red</font> <font color=\"#00ff00\">green</font>";
Spanned result = Html.fromHtml(formattedText);
view.setText(result);
Or, use spannable like in Set color of TextView span in Android
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. :)