我想知道是否有任何好的选择可以在 Android 中实现 富文本编辑器.请注意,我说的是可以在 Android 应用程序中使用的富文本编辑器,而不是使用 HTML 和 Javascript 嵌入网页中的编辑器.
I am wondering if there are any good options to implement a rich text editor in Android. Please note I am talking about a rich text editor that can be used in an Android application, not the one embedded in a web page using HTML and Javascript.
我的要求是:
如您所见,这与 Windows 上的典型 RichEdit 控件非常相似.
As you can see, this is pretty much something quite similar to a typical RichEdit control on Windows.
以下是我迄今为止所做的一些努力(调查和原型设计):
Here are some efforts (investigation & prototyping) I have made so far:
我尝试使用 WebView 控件加载一个带有 .内容变得可编辑,因为它是 HTML,我想它可以满足我的大部分要求.但它有几个问题:
I have tried using a WebView control to load an HTML fragment with one . The content becomes editable and as it is HTML, I suppose it can meet most of my requirements. But it has several issues:
我尝试过使用 EditText 控件.它似乎支持某种程度的富文本编辑(颜色、字体、粗体、斜体、下划线、内嵌图像、项目符号列表).但我仍然无法弄清楚如何实现以下要求:
I have tried using the EditText control. It seems to support some level of rich text editing (color, fonts, bold, italic, underline, inline images, bullet lists). But I still cannot figure out how I can implement the following requirements:
顺便说一句,我已经看到那里有几个 *Span 类,但我不确定它们是否可以提供任何帮助......以及 http://developer.android.com 没有提供太多有用的信息.
BTW, I have seen there are several *Span classes out there but I am not sure if they can be any help... And the http://developer.android.com does not provide much useful information about them.
那么,究竟如何在 Android 上实现富文本编辑器呢?我可以扩展 EditText 并添加我的新功能吗?还是我应该从头开始做一些事情 - 扩展视图并自己实现一切?对于后面的选项(扩展视图),我什至不知道如何显示文本插入符号并使其闪烁,更不用说在用户输入时移动插入符号了.
So, how on earth can I implement a rich text editor on Android? Can I extends the EditText and add my new functionalities? Or should I do something from scratch - extends the View and implement everything by myself? For later option (extending View), I actually even don't know how to show a text caret and blink it, not mentionging moving the caret with user typing.
我现在很绝望……有什么提示吗?
I am desperate now... Any hints?
谢谢!
-托尼
经过进一步调查,看起来扩展 EditText 是我最好的选择.我不知何故想出了如何使用这些 Span 类,并猜测我应该能够通过使用(扩展)它们来完成大部分技巧.
After some further investigation, it looks like extending EditText would be my best bet. I somehow figured out how to use those Span classes and guess I should be able to do most of the tricks by using (extending) them.
例如,扩展 BulletSpan 并覆盖 drawLeadingMargin 应该可以让我控制项目符号的外观.扩展LeadingMarginSpan 应该对我的编号列表有所帮助.
For example, extending the BulletSpan and overriding drawLeadingMargin should give me the control of the bullet appereances. Extending the LeadingMarginSpan should help me on the numbered list.
对于表格,我最初的计划是扩展 LineBackgroundSpan 并在 drawBackground 覆盖中绘制所有表格边框.但是,我仍然需要弄清楚如何布局表格单元格中的所有文本并正确处理插入符号的移动和选择.有什么建议吗?
As to the table, my initial plan is to extend the LineBackgroundSpan and draw all the table borders in the drawBackground override. However, I still need to figure out how to layout all the text in the table cells and properly handle the caret movement and selection. Suggestions?
我刚刚在 Apache 2.0 许可下发布了我的富文本编辑器组件:
I just published my rich text editor component under the Apache 2.0 license:
https://github.com/1gravity/Android-RTEditor
这篇关于在 Android 中实现富文本编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!