Commit 583ff668 authored by sendtion's avatar sendtion Committed by GitHub

增加gradle依赖和Maven依赖

增加gradle依赖和Maven依赖方式
parent 4d36e3d6
# XRichText # XRichText
[![](https://jitpack.io/v/sendtion/XRichText.svg)](https://jitpack.io/#sendtion/XRichText)
一个Android富文本类库,支持图文混排,支持编辑和预览,支持插入和删除图片。 一个Android富文本类库,支持图文混排,支持编辑和预览,支持插入和删除图片。
### 实现的原理: ### 实现的原理:
...@@ -12,38 +14,68 @@ ...@@ -12,38 +14,68 @@
![笔记详情](http://img.blog.csdn.net/20161026140122507) ![笔记详情](http://img.blog.csdn.net/20161026140122507)
## 使用方式 ## 使用方式
1. 作为类库 #### 1. 作为module导入
把xrichtext作为一个module导入你的工程。 把xrichtext作为一个module导入你的工程。
把xrichtext中的文件拷贝到你的工程,可以在你的工程中建一个xrichtextming包名,并把文件拷贝进去。
2. gradle依赖 #### 2. gradle依赖
稍后支持。
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.sendtion:XRichText:1.0'
}
```
#### 3. Maven方式
```
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.sendtion</groupId>
<artifactId>XRichText</artifactId>
<version>1.0</version>
</dependency>
```
## 具体使用 ## 具体使用
在xml布局中添加基于EditText编辑器(可编辑) 在xml布局中添加基于EditText编辑器(可编辑)
```
<com.sendtion.xrichtext.RichTextEditor <com.sendtion.xrichtext.RichTextEditor
android:id="@+id/et_new_content" android:id="@+id/et_new_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:textSize="@dimen/text_size_16" android:textSize="@dimen/text_size_16"
android:textColor="@color/grey_600"/> android:textColor="@color/grey_600"/>
```
在xml布局中添加基于TextView编辑器(不可编辑) 在xml布局中添加基于TextView编辑器(不可编辑)
```
<com.sendtion.xrichtext.RichTextView <com.sendtion.xrichtext.RichTextView
android:id="@+id/tv_note_content" android:id="@+id/tv_note_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:textSize="@dimen/text_size_16" android:textSize="@dimen/text_size_16"
android:textColor="@color/grey_600"/> android:textColor="@color/grey_600"/>
```
**我把数据保存为了html格式,生成字符串存储到了数据库。** **我把数据保存为了html格式,生成字符串存储到了数据库。**
### 生成数据 ### 生成数据
```
String noteContent = getEditData();
String noteContent = getEditData(); private String getEditData() {
private String getEditData() {
List<RichTextEditor.EditData> editList = et_new_content.buildEditData(); List<RichTextEditor.EditData> editList = et_new_content.buildEditData();
StringBuffer content = new StringBuffer(); StringBuffer content = new StringBuffer();
for (RichTextEditor.EditData itemData : editList) { for (RichTextEditor.EditData itemData : editList) {
...@@ -54,18 +86,19 @@ ...@@ -54,18 +86,19 @@
} }
} }
return content.toString(); return content.toString();
} }
```
### 显示数据 ### 显示数据
```
et_new_content.post(new Runnable() { et_new_content.post(new Runnable() {
@Override @Override
public void run() { public void run() {
showEditData(content); showEditData(content);
} }
}); });
protected void showEditData(String content) { protected void showEditData(String content) {
et_new_content.clearAllLayout(); et_new_content.clearAllLayout();
List<String> textList = StringUtils.cutStringByImgTag(content); List<String> textList = StringUtils.cutStringByImgTag(content);
for (int i = 0; i < textList.size(); i++) { for (int i = 0; i < textList.size(); i++) {
...@@ -84,7 +117,8 @@ ...@@ -84,7 +117,8 @@
et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), text); et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), text);
} }
} }
} }
```
### 具体的使用方式,请参考Demo代码。 ### 具体的使用方式,请参考Demo代码。
...@@ -99,3 +133,20 @@ ...@@ -99,3 +133,20 @@
- CSDN:http://blog.csdn.net/shuyou612 - CSDN:http://blog.csdn.net/shuyou612
- GitHub:https://github.com/sendtion - GitHub:https://github.com/sendtion
- 欢迎大家fork、star,也欢迎大家参与修改。 - 欢迎大家fork、star,也欢迎大家参与修改。
## License
```
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment