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.
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 have a Textview with some texts. So if the line count is more than two i have to fade some characters at the end of second line.
How can we do something like that?
You can use html font color like that :
String text = textView.getText().toString();
String a = text.substring(0, text.length()-2);
String b = text.substring(text.length()-2, text.length()-1);
String c = text.substring(text.length()-1, text.length());
text = "<font color=#000000>"+a+"</font><font color=#777777>"+b+"</font>"+"<font color=#AAAAAA>"+c+"</font>";
textView.setText(Html.fromHtml(text));
Result screenshot :
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
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