I'm using AutoResizeTextView library .it is working fine on String like
String text="Some text goes here";
textview.setText(text);
But when i try to write
String text="Some text \n goes here";
textview.setText(text);
it takes the text to nextline but sets the size to minimum
Related
I am displaying text in a textview without using toString(), to keep the formatting(bold, underline, italics) within the text. But now I want to set different font sizes to _etheadertext ,_etheadertext3 etc..
String header = _etheadertext.getText() + "\n" + _etheadertext3.getText() + "\n" + _etheadertext4.getText() + "\n" + _etheadertext5.getText();
You can use text Spans to apply formatting to parts of a string.
SpannableString spannablecontent=new SpannableString(content.toString());
//set a Style Span to apply Typeface style
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),
0,spannablecontent.length(), 0);
You can set RelativeSizeSpan to change the text sizes if required.
And then finally, set the spanned string in a TextView.
mTextView.setText(spannablecontent);
I want to change text color before displaying it to TextView.
For example,I am getting a text from server like
<b>Pratik<b/> has shared photo with <b>you</b>.
Now the requirements are to display Pratik and you with Bold style and Blue text color. I tried several ways using <span> tag, but I am not getting clear way to display it.
String htmlBody = "<b>Pratik<b/> has shared photo with <b>you</b>.";
String formattedBody = "<span>" + htmlBody + "</span><style>b { color: #309ce8 ; } span {font-family: 'Avenir', 'Heavy'; font-size: 17; }</style>";
SpannableString text = new SpannableString(formattedBody);
tvMessage.setText(text, TextView.BufferType.SPANNABLE); // This is not working as expected.
tvMessage.setText(Html.fromHtml(htmlBody)); // This is not working as expected.
Help me achieve that.
String htmlBody = "<b style='color:blue !important;'>Pratik</b> has shared photo with <b style='color:blue !important;'>you</b>.";
Your Solution is:
String styledText = "<b><font color='red'>Pratik</font><b/> has shared photo with <b><font color='red'>you</font></b>";
You have to use like this
public void methodName() {
String html = "Some text <b>here</b>, and some <b>there</b>";
String result = html.replace("<b>","<font color=\"#ff0000\"><b>").replace("</b>", "</b></font>");
textView.setText(Html.fromHtml(result));
}
I have a String I have to display in a TextView with Html.fromHtml(), but it contains sometimes a few \n at the end of the text, so TextView shows empty lines.
I tried to remove \n by
text = text.replace('\n', ' ');
text = text.replace("\n", "");
text = text.replace("\\n", "");
text = text.replaceAll("\\n", "");
text = text.replaceAll("\\\\n", "");
than I insert the text into TextView like this
tv.setText(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY, null, new CustomTagHandler(context, cp)));
But non of these removed the \n from the end of the text. When I check my layout at Layout inspector I can see the TextView's content, and the \n at the end of the text.
i have one EditText and entered some text.
view.editText.setTextColor(Color.RED);
Html.toHtml(editText.getText())
convert it to html text.
o/p
text color change
i have getting only paragragh but not the selected color.
Because,
editText.getText() just returns Editable character sequence not a Html rich string.
String sample=editText.getText();
TextView str = new TextView(null);
str.setText(sample);
str.setTextColor(Color.RED);
editText.setText(str.getText().tostring());
or use this
Html.fromHtml("<font color = #ffffff>"
+ getResources().getString(editText.getText().tostring()) + "</font>")
thank you.
I need to print the below string which is in Arabic on TextView in Android. It is printing good but when the Arabic text and digits falls in a same string, Android put the digit at end!
here is my code
String str = "مقر 44";
TextView textView = (TextView)findViewById(R.id.test);
textView.setText(str);
Here is the output
you can try with this workaround
String str = "44 "+"مقر ";
TextView textView = (TextView)findViewById(R.id.txt_title);
textView.setText(str);
its not Android who put digit at the end, its because of Arabic writing standard