android图文混排编辑器,Android富文本编辑器,支持图文混排,支持插入和删除图片...

XRichText

截图预览

?p=447

?p=447

?p=447

使用方式

1、作为类库

把 xrichtext 作为一个 module 导入你的工程。

或者

把 xrichtext 中的文件拷贝到你的工程,可以在你的工程中建一个 xrichtextming 包名,并把文件拷贝进去。

在 xml 布局中添加基于 EditText 编辑器(可编辑):

<com.sendtion.xrichtext.RichTextEditor

android:id="@+id/et_new_content"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:textSize="@dimen/text_size_16"

android:textColor="@color/grey_600"/>

在 xml 布局中添加基于 TextView 编辑器(不可编辑):

<com.sendtion.xrichtext.RichTextView

android:id="@+id/tv_note_content"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:textSize="@dimen/text_size_16"

android:textColor="@color/grey_600"/>

我把数据保存为了 html 格式,生成字符串存储到了数据库。

生成数据:

String noteContent = getEditData();

private String getEditData() {

List<RichTextEditor.EditData> editList = et_new_content.buildEditData();

StringBuffer content = new StringBuffer();

for (RichTextEditor.EditData itemData : editList) {

if (itemData.inputStr != null) {

content.append(itemData.inputStr);

} else if (itemData.imagePath != null) {

content.append("<img src="").append(itemData.imagePath).append(""/>");

}

}

return content.toString();

}

显示数据:

et_new_content.post(new Runnable() {

@Override

public void run() {

showEditData(content);

}

});

protected void showEditData(String content) {

et_new_content.clearAllLayout();

List<String> textList = StringUtils.cutStringByImgTag(content);

for (int i = 0; i < textList.size(); i++) {

String text = textList.get(i);

if (text.contains("<img")) {

String imagePath = StringUtils.getImgSrc(text);

int width = ScreenUtils.getScreenWidth(this);

int height = ScreenUtils.getScreenHeight(this);

et_new_content.measure(0,0);

Bitmap bitmap = ImageUtils.getSmallBitmap(imagePath, width, height);

if (bitmap != null){

et_new_content.addImageViewAtIndex(et_new_content.getLastIndex(), bitmap, imagePath);

} else {

et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), text);

}

et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), text);

}

}

}

2、gradle 依赖

稍后支持。

风的记忆 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权

转载请注明原文链接:Android 富文本编辑器,支持图文混排,支持插入和删除图片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值