Maybe the best rich text editor on android platform. Base on Simditor
- Alignment (left/center/right)
- Bold
- Blockquote
- Code
- Horizontal ruler
- Italic
- Image
- Indent
- Link
- Outdent
- Ordered List
- Unordered List
- Underline
- Raw html (Insert anything to any selection range that you want via API)
Add this line to your build.gradle file under your module directory.
compile 'com.github.mr5:icarus:0.1.14'Java codes:
importandroid.app.Activity;
importandroid.webkit.WebView;
importandroid.widget.TextView;
importcom.github.mr5.icarus.entity.Options;
importcom.github.mr5.icarus.button.TextViewButton;
classEditorActivityextendsActivity {
protectedWebViewwebView;
protectedIcarusicarus;
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
// Get WebView from your layout, or create it manually.setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.editor);
// I offered a toolbar to manage editor buttons which implements TextView that with icon fonts. // It's just a collection, not an Android View implementation. // TextViewToolbar will listen click events on all buttons that added to it. // You can implement your own `Toolbar`, to prevent these default behaviors.TextViewToolbartoolbar = newTextViewToolbar();
Optionsoptions = newOptions();
options.setPlaceholder("Placeholder...");
icarus = newIcarus(toolbar, options, webView);
TextViewboldButton = newTextViewButton()
boldButton.setName(Button.NAME_BOLD);
toolbar.addButton(boldButton);
icarus.render();
}
}see Button.java
Placeholder of Editor. Use the placeholder attribute value of the textarea by default.
default: "Icarus editor."
Example:
options.setPlaceholder("Input something...");Default image placeholder. Used when inserting pictures in Edtior.
default: "images/image.png"
Example:
options.setDefaultImage("file:///android_asset/xxx.jpg");Remove all styles in paste content automatically.
default: false
Example:
options.setCleanPaste(true);Tags that are allowed in Editor
default: {"br", "span", "a", "img", "b", "strong", "i", "strike", "u", "font", "p", "ul", "ol", "li", "blockquote", "pre", "code", "h1", "h2", "h3", "h4", "hr"}
Example:
// option replacement.options.setAllowedTags(Arrays.asList("a", "span", "img");
// add tag to current tag list.options.addAllowedTag("pre");Whitelist of tag attributes. Note that custom whitelist will be merged into the default one.
default:
img: {"src","alt","width","height","data-non-image"}
a: {"href","target"}
font: {"color"}
code: {"class"}Example:
// option replacement.options.setAllowedAttributes(newHashMap<String, List<String>>());
// add new attribute to current tag list.options.addAllowedAttributes("a", Arrays.asList("class", "src", "alt", "data-type"));icarus.loadCSS("file:///android_asset/editor.css");
icarus.loadJs("file:///android_asset/test.js");Some buttons depend user's actions, such as Button.NAME_LINK, Button.NAME_IMAGE. So you want to show a popover for user to do these actions. Icarus offered 3 Popover Implementations, HtmlPopoverImpl, ImagePopoverImpl, LinkPopoverImpl,
Samples:
TextViewimageButtonTextView = (TextView) findViewById(R.id.button_image);
imageButtonTextView.setTypeface(iconfont);
TextViewButtonimageButton = newTextViewButton(imageButtonTextView, icarus);
imageButton.setName(Button.NAME_IMAGE);
imageButton.setPopover(newImagePopoverImpl(imageButtonTextView, icarus));
toolbar.addButton(imageButton);You can implement your own popover to handler user's actions.
icarus.insertHtml("<iframe src=\\"xxx\\"></iframe>");// Get contentsicarus.getContent(newCallback() {
@Overridepublicvoidrun(Stringparams) {
Gsongson = newGson();
Htmlhtml = gson.fromJson(params, Html.class);
Log.d("Content gotten", html.getContent());
}
});
// Set contentsicarus.setContent("new content");
