使用edittext作为android中的html编辑器



我正在创建一个应用程序,该应用程序提供了撰写文章和提交的选项。

我想给用户所有的html选项,这样用户就可以将部分文本加粗、斜体、下划线等。我在谷歌上搜索了一下,但没有找到太多适合android的选项或任何html工具。

寻求建议。

您可以使用以下内容:

这里textDisplayedBottom是一个TextView。

actualStringToDisplay="font COLOR="RED"><b>"+yourString</b></font>"; 
textDisplayedBottom.setText(Html.fromHtml(actualStringToDisplay));

希望这能有所帮助。

编辑1:用于编辑文本

对于提供粗体-斜体下划线选项的编辑文本,您可以始终使用Spannable来实现

// Get our EditText object.
EditText vw = (EditText)findViewById(R.id.text);
// Set the EditText's 
text.vw.setText("Italic, highlighted, bold.");
// If this were just a TextView, we could do:
// vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE);
// to force it to use Spannable storage so styles can be attached.
// Or we could specify that in the XML.
// Get the EditText's internal text storage
Spannable str = vw.getText();
// Create our span sections, and assign a format to each.
str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

您可以在这里找到详细信息

http://developer.android.com/resources/faq/commontasks.html#selectingtext

最新更新