2015-09-28 44 views
0

我有一个需要富文本编辑器的应用程序。添加复选框到edittext/textview?

我打算实现这个使用spannables或分配一个html代码作为textview的文本。

我可以用同样的方法添加复选框吗?

+0

一些示例图像会有所帮助。 –

+0

你想为复选框设置文本或什么? – mixel

+0

如果有任何答案帮助您考虑upvote或接受它。 – mixel

回答

0

要显示TextView HTML,你应该使用Html.fromHtml()首先转换为Spanned。但是在这种方法中只能使用一个小的HTML标签子集,因为spannables用于样式文本。如果你想添加复选框,那么你应该在TextView以外做这个。

+0

在允许列表中不可用? – SadeepDarshana

+0

不,只有'a,b,big,blockquote,br,cite,dfn,div,em,font,i,img,p,small,strong,sub,sup,tt,u'标签。对于'img'标签,你必须包含'ImageGetter'。更多信息http://daniel-codes.blogspot.ru/2011/04/html-in-textviews.html – mixel

0

至于CheckBoxTextView延伸你可以使用setText方法与你Spannable

例如:

SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(poweredBy + " " + company); 
    int start = poweredBy.length(); 
    int end = spannableStringBuilder.length(); 
    spannableStringBuilder.setSpan(new ForegroundColorSpan(companyColor), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
    checkbox.setText(spannableStringBuilder); 
+0

“CheckBox从TextView扩展”是什么意思? – SadeepDarshana

+0

@ user2495720根据CheckBox类的层次结构:CheckBox - > CompoundButton - > Button - > TextView。 setText方法是在TextView中实现的一种方法,这意味着此功能也适用于CheckBox – Oleksandr