AndroidAnnotations——Injecting html注入html文本

109人阅读 评论(0) 收藏 举报

Injecting html注入html

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:
假如你想在 TextView 控件中注入HTML文本(可能它需要格式化,或者因为你喜欢HTML ),有两个注解可以帮助你:
  • @FromHtml
  • @HtmlRes

Let's say you have the following string resource:
让我们假设你有以下的string资源:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello_html"><![CDATA[Hello <b>World</b>!]]></string>
</resources>

@HtmlRes


This annotation acts as @StringRes (retrieves a String resource) and wraps the result with a call to HTML.fromHtml():
这个注解表现的和 @StringRes 类似(获取 String 资源)并调用 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 implements CharSequence, thus you can use both for a @HtmlRes.请注意 Spanned 实现了 CharSequence,因此你可以用 @HtmlRes注解它们。

@FromHtml


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:
这个注解必须在加了 @ViewById 注解的 TextView 上使用。它的目的是设置HTML文本到 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;

}

本文档的简单示例下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值