Knife (extend EditText) is a rich text editor component for writing documents in Android.
Just select text and use one line code to style it!
Support Android 4.0+
Here has a demo apk, and it's source code, very easy to understand~
More experiments see mthli/Type.
-
bold(boolean valid)
bold the selected text. -
italic(boolean valid)
italic the selected text. -
underline(boolean valid)
<u>underline</u> the selected text. -
strikethrough(boolean valid)
strikethroughthe selected text. -
bullet(boolean valid)
bullet the selected text. -
quote(boolean valid)
quote the selected text. -
link(String link)
andlink(String link, int start, int end)
to link the text. -
contains(int FORMAT)
returntrue
if the selected text contains the FORMAT. -
clearFormats()
clear all formats. -
redo()
when text changed, you can redo it! -
undo()
when text change, you can also undo it! -
fromHtml()
import from HTML file. -
toHtml()
export as HTML file.
If you want to get more control of the editable text, just extend KnifeText to get all protected method.
-
app:bulletColor
-
app:bulletRadius
-
app:bulletGapWidth
-
app:historyEnable
true
to enable record history, so you canredo()
andundo()
. -
app:historySize
the record max limit. -
app:linkColor
-
app:linkUnderline
true
to enable link underline. -
app:quoteColor
-
app:quoteStripeWidth
the quote line width. -
app:quoteCapWidth
- Insert image.
At your top-level build.gradle
file:
repositories {
// ...
maven { url 'https://jitpack.io' }
}
And then at your project build.gradle
file:
dependencies {
compile 'com.github.mthli:Knife:v1.1'
}
Done!
Copyright 2015 Matthew Lee
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.