This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
Injecting html
pyricau edited this page Jan 14, 2012
·
8 revisions
Since AndroidAnnotations 2.2
If you want to inject HTML text in a TextView
(may it be to format it or because you love HTML), there are two annotations that can help you:
@FromHtml
@HtmlRes
Let's say you have the following string resource:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello_html"><![CDATA[Hello <b>World</b>!]]></string>
</resources>
This annotation acts as @StringRes (retrieves a String
resource) and wraps the result with a call to HTML.fromHtml()
:
@EActivity
public class MyActivity extends Activity {
// Injects R.string.hello_html
@HtmlRes(R.string.hello_html)
Spanned myHelloString;
// Also injects R.string.hello_html
@HtmlRes
CharSequence helloHtml;
}
Note that
Spanned
implementsCharSequence
, thus you can use both for a@HtmlRes
.
This annotation must be used on a TextView
already annotated with @ViewById
. The purpose of this annotation is to set HTML text in a TextView:
@EActivity
public class MyActivity extends Activity {
@ViewById(R.id.my_text_view)
@FromHtml(R.string.hello_html)
TextView textView;
// Injects R.string.hello_html into the R.id.hello_html view
@ViewById
@FromHtml
TextView helloHtml;
}
19/11/2020 The 4.8.0 release is out !
- Get started!
- Cookbook, full of recipes
- Customize annotation processing
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow
- Ask on Gitter