基于wangEditor 在Android实现的富文本功能
- | - | ||
- | - |
Add it in your root build.gradle at the end of repositories:
maven { url 'https://jitpack.io' }
Step 2. Add the dependency
dependencies {
implementation 'com.github.SheTieJun:wangEditor-Android:Tag'
//或者
implementation `com.github.SheTieJun.wangEditor-Android:rich_editor:Tag`
implementation `com.github.SheTieJun.wangEditor-Android:editor_toolbar:Tag`
}
<com.wangeditor.android.WangRichEditor
android:id="@+id/rich_Editor"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
editor.setEditorHeight(200); //dp = html px
editor.setEditorFontSize(22); //android dp = html px
editor.setEditorFontColor(Color.RED);
editor.setEditorBackgroundColor(Color.BLUE);
editor.setPadding(10, 10, 10, 10); //android dp = html px
mViewBinding.richEditor.setInputEnabled(enable) //是否编辑状态
initKeyboardChange
,可以自行重写使用
主要是为了修复打开键盘的时候,无法自动滚到选中的位置
默认实现操作:
<com.wangeditor.android.toolbar.RichEditorToolbar
android:id="@+id/editToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
editToolbar.setEditor(mViewBinding.richEditor)
editToolbar.initTextStyle()
editToolbar.initFunStyle()
editToolbar.initParagraphStyle()
editToolbar.initMedia()
API参考项目:richeditor-android
核心内容:wangeditor
wangEditor不支持低版本的Chrome,如果主要用户群体是消费水平低的人的话,不建议使用这个库
为什么不用X5,1. X5是动态加载的,内核由于包大小较大,存在一定失败率,也就是说用户可能会存在无法使用的情况 2.如果你要上架google,那么就不能使用X5
如果存在个别用户Chrome版本过低,可以在下面的链接下载apk给用户安装,~需要梯子 android-system-webview.APK
其中的交互部分wang_app_editor.js
可以在iOS上通用,就是说iOS可以复制使用相关功能,不过可能需要修改部分调用native的方法部分。
为什么项目中没有使用原生Span实现,主要原因是标签解析的问题。 原生我也实现了一版demo,大部分功能都已实现,发现中间会有很多意外的情况需要进行处理,例如颜色rgb,arg,#fff。
为什么使用wangEditor
, 这是考虑多端处理的结果,其中web端使用了wangEditor
项目进行开发的,我尝试移植后发现也可以使用,这样可以保证相同的格式处理问题。
wangEditor
功能很全,但是我只懂皮毛的js
和html
,所以我这里只用到部分的功能,还有部分功能被我移除了,我用的是simple
缺点:
wang_editor_index.js
体积太大,功能内容太多,已我的知识储备无法进行优化简化,同时不支持低版本chrome优化:
wangEditor
功能齐全强大,后续可以功能同步web
大图不要用base64插入,否则会很卡顿
核心文件:wang_app_editor.js
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。