How to display a Textview with highlighting a specific text like first letter i need bold in style
textview.setText(Html.fromHtml( < b>A< /b>ndroid));
Related
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 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
Suppose I have TextView and I want to change color of some part in it. Like this
And I must set OnclickListener on text " Terms Of Use ", so How can I do that but using two textViews. Thanks
Regards
Use a simple Checkbox with no text, and for text clicking event
this is what you are looking for Spannable
You can youse HTML in TextView:
myTextView.setText(Html.fromHtml("<h2>Test</h2>"));
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?
I am creating one application in which I am searching for a Perticular word in text view.I have one edit text,one text view and one button,when I am entering any word in edit text and clicking on button it gives me the line position and position of word in that line from entire text file...I have append text file's contain in text view...now my question is can I highlight that all word which is there in text view entered by edit text.?if I can than please tell me how to do it..if any one have idea of it?
You can also do it by using a Spannable, which is convenient as you know the position of the word:
SpannableString res = new SpannableString(entireString);
res.setSpan(new ForegroundColorSpan(color), start, end, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
Where entireString is the string in which the word to highlight exists, color is the color you want the hightlighted text to have, start is the position of the word and end is where the word ends (start+word.length()).
The SpannableString res can then be applied to your textview like a regular string:
textView.setText(res);
Note: If you want the background of the text to get a color rather than the text itself, use a BackgroundColorSpan instead of a ForegroundColorSpan.
Edit:
In your case it would be something like this (you will have to save the value of linecount and indexfound for when you read the entire text):
for(String test="", int currentLine=0; test!=null; test=br2.readLine(), currentLine++){
if(currentLine==linecount){
SpannableString res = new SpannableString(test);
res.setSpan(new ForegroundColorSpan(0xFFFF0000), indexfound, indexfound+textword.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
}
tv.append("\n"+" "+test);
}
Yes You can highlight some portion of the text view by writing HTML
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
use Spannable to set text in spannable you can setSpan by which you can highlight the text you want
string ="<font color='#ff0000' > <b>hello</b> </font>"
textview.setText(Html.fromHtml(string))
http://developer.android.com/reference/android/text/Html.html