forked from androidannotations/androidannotations
-
Notifications
You must be signed in to change notification settings - Fork 0
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
SpannedimplementsCharSequence, 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;
}AndroidAnnotations was created by Pierre-Yves Ricau and is sponsored by eBusinessInformations.
04/03/2013 The 2.7.1 release is out
- Get started!
- Download
- Cookbook, full of recipes
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow