[英]Implementing a rich text editor in Android?
I am wondering if there are any good options to implement a rich text editor in Android. 我想知道是否有任何好的选择可以在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.
请注意,我所说的是一种可以在Android应用程序中使用的富文本编辑器,而不是使用HTML和Javascript嵌入在网页中的富文本编辑器。
My requirements are: 我的要求是:
As you can see, this is pretty much something quite similar to a typical RichEdit control on Windows. 如您所见,这几乎类似于Windows上的典型RichEdit控件。
Here are some efforts (investigation & prototyping) I have made so far: 到目前为止,我已经做了一些努力(调查和原型设计):
I have tried using a WebView control to load an HTML fragment with one . 我尝试使用WebView控件加载带有HTML片段的HTML片段。 The content becomes editable and as it is HTML, I suppose it can meet most of my requirements.
内容变成可编辑的,因为它是HTML,所以我想它可以满足我的大多数要求。 But it has several issues:
但这有几个问题:
I have tried using the EditText control. 我尝试使用EditText控件。 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:
但是我仍然不知道如何实现以下要求:
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. 顺便说一句,我已经看到那里有几个* Span类,但是我不确定它们是否有帮助...而且http://developer.android.com没有提供有关它们的很多有用信息。
So, how on earth can I implement a rich text editor on Android? 那么,到底如何在Android上实现富文本编辑器? Can I extends the EditText and add my new functionalities?
我可以扩展EditText并添加新功能吗? 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? 我现在很绝望...有什么提示吗?
Thanks! 谢谢!
-Tony -托尼
After some further investigation, it looks like extending EditText would be my best bet. 经过进一步调查,似乎扩展EditText将是我最好的选择。 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.
我以某种方式弄清楚了如何使用那些Span类,并猜想我应该能够通过使用(扩展)它们来完成大多数技巧。
For example, extending the BulletSpan and overriding drawLeadingMargin should give me the control of the bullet appereances. 例如,扩展BulletSpan并覆盖drawLeadingMargin应该可以控制子弹外观。 Extending the LeadingMarginSpan should help me on the numbered list.
扩展LeadingMarginSpan应该可以帮助我在编号列表上。
As to the table, my initial plan is to extend the LineBackgroundSpan and draw all the table borders in the drawBackground override. 对于表格,我的最初计划是扩展LineBackgroundSpan并在drawBackground替代中绘制所有表格边框。 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?
有什么建议吗?
I just published my rich text editor component under the Apache 2.0 license: 我刚刚在Apache 2.0许可下发布了富文本编辑器组件:
https://github.com/1gravity/Android-RTEditor https://github.com/1gravity/Android-RTEditor
如果需要进行足够大的更改,我可能会同时扩展EditText
和TableLayout
或者至少最终使用它们的大部分源代码 。
Can you do the following: 您可以执行以下操作:
To me seems like if you have to muck about with the layout, are you better off writing it from scratch on your own. 在我看来,如果您不得不考虑布局问题,那么最好还是自己重新编写。 From what I remember the Edit text (and the richt text editor) is great for anything where you the data is pure text.
从我记得的情况来看,“编辑”文本(和Richt文本编辑器)非常适合任何您将数据作为纯文本的情况。
There is an open source EditText rich text editor called android-richtexteditor but the code was inexplicably deleted in r5. 有一个名为android-richtexteditor的开源EditText RTF编辑器,但是在r5中莫名其妙地删除了代码。 The code is still there in r4 ;
代码仍然在r4中 ; just use svn to check out r4 or earlier to access it.
只需使用svn签出r4或更早版本即可访问它。 The code appears to support italics, underline, color picker, text size, and more.
该代码似乎支持斜体,下划线,颜色选择器,文本大小等。
You can make use of any of the following libraries:- 您可以使用以下任何一个库:
https://github.com/commonsguy/cwac-richedit https://github.com/commonsguy/cwac-richedit
https://github.com/chinalwb/Android-Rich-text-Editor https://github.com/chinalwb/Android-Rich-text-Editor
https://github.com/wasabeef/richeditor-android https://github.com/wasabeef/richeditor-android
https://github.com/irshuLx/Android-WYSIWYG-Editor https://github.com/irshuLx/Android-WYSIWYG-Editor
Extend from EditText is a best choice for you, it support CharacterSpan and ParagraphSpan. 从EditText扩展是最适合您的选择,它支持CharacterSpan和ParagraphSpan。
See my App on the Google Play: https://play.google.com/store/apps/details?id=com.hly.notes 在Google Play上查看我的应用程序: https : //play.google.com/store/apps/details?id=com.hly.notes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.