RTextEditorView
A simple WYSIWYG Editor for Android based on Summernote.
Screenshots
Features
- Font Name
- Font Size
- Line Spacing
- Bold
- Italic
- Underline
- Strikethrough
- Paragraph
- Heading 1-6
- Superscript
- Subscript
- Text Foreground Color
- Text Background Color
- Unordered List
- Ordered List
- Blockquote
- Block Code
- Left Align
- Center Align
- Right Align
- Justify Align
- Horizontal Rule
- Indent
- Outdent
- Clear Formatting
- Edit HTML
- Insert Image
- Insert Table
- Insert Link
- Remove Link
- Get/Set HTML
- Undo/Redo changes
Download
Download the latest AAR or grab via Gradle:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven {
url 'https://jitpack.io'
}
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.jkennethcarino:RTextEditorView:0.1.1'
}
RTextEditorView requires at minimum Android 4.0.3 (API Level 15).
Usage
XML usage:
<!-- Set up the main editor --> <com.jkcarino.rtexteditorview.RTextEditorView
android:id="@+id/editor_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/toolbar_line"
android:layout_alignParentTop="true" /> <!-- Set up the toolbar --> <com.jkcarino.rtexteditorview.RTextEditorToolbar
android:id="@+id/editor_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.jkcarino.rtexteditorview.RTextEditorButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:padding="@dimen/toolbar_item_padding"
app:srcCompat="@drawable/ic_format_bold"
app:toolType="bold" />
<com.jkcarino.rtexteditorview.RTextEditorButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:padding="@dimen/toolbar_item_padding"
app:srcCompat="@drawable/ic_format_italic"
app:toolType="italic" /> </com.jkcarino.rtexteditorview.RTextEditorToolbar>
Java usage:
RTextEditorView editor = (RTextEditorView) findViewById(R.id.editor_view);
RTextEditorToolbar editorToolbar = (RTextEditorToolbar) findViewById(R.id.editor_toolbar);
// Set the RTextEditorView to our toolbar editorToolbar.setEditorView(editor);
And you're good to go!
You can implement your own toolbar, or just use a simple Button
:
Button boldButton = (Button) findViewById(R.id.format_bold);
boldButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editor.setBold();
// or editor.setFormat(ToolType.BOLD);
}
}
);
Set Text Change Listener:
RTextEditorView editor = (RTextEditorView) findViewById(R.id.editor_view);
editor.setOnTextChangeListener(new RTextEditorView.OnTextChangeListener() {
@Override
public void onTextChanged(String content) {
Log.d("RTextEditorView", "onTextChanged: " + content);
}
}
);
To see it in action, check out the sample app in sample/
or download the sample APK.
Credits
- RichEditor
- MRichEditor
- Color Picker
- Google and Austin Andrews for the Material Design Icons that I used in the sample app.
License
MIT License Copyright (c) 2017 Jhon Kenneth CariƱo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.