How Display Formatted Text In Edittext?
Now I am writing simple note app. And i need to display formatted separate selected text in EditText. I tried, EditText et = (EditText)findViewById(R.id.edittext); String string;
Solution 1:
Try this
EditText text = new EditText(this);
text.setText(Html.fromHtml(html));
text.setMovementMethod(LinkMovementMethod.getInstance());
Solution 2:
try using this
Stringstring = et.getText().toString();
String selectedString = string.substring(startSelection, endSelection);
Spanned s = Html.fromHtml(string.replace(selectedString, "<font color=\"red\">" + selectedString + "</font>"));
Solution 3:
If you talking about formatting the Text, You can always do like this
EditTextet=newEditText(this);
et.setText(Html.fromHtml("Simple Text <B>Formatted Text</B> Simple Text Again"));
And If you want to linkify
a specific part of the Text then do it like this using this Blog
EditTextmTextSample=newEditText(this);
Stringtext="click to see stackoverflow.com here";
mTextSample.setText(text);
Patternpattern= Pattern.compile("stackoverflow.com");
Linkify.addLinks(mTextSample, pattern, "http://");
Post a Comment for "How Display Formatted Text In Edittext?"