This library is a representation of Android Rich text Editor based on Android native classes. This build offers an optimized library reimplemented in Kotlin
by using Material Design Components.
Currently, it does not include all features introduced in the original library. But nevertheless, they will be added release by release. Currently available features in :
- Bold
- Italic
- Underline
- Strikethrough
- Text size
- Foreground color
- Link/Phone numbers/Emails
First add this in to root build.gradle
at the end of repositories :
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then add this dependency in your apps build.gradle
:
implementation 'com.github.easy-apps-2018:rich-editor-lib:0.1.1'
In XML
: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.easyapps.richeditorlib.widgets.RichEditText
android:id="@+id/richEditText"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="16dp"
android:background="@null"
app:layout_constraintBottom_toTopOf="@+id/styleBar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<com.easyapps.richeditorlib.widgets.StyleBar
android:id="@+id/styleBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
In Kotlin
class: MainActivity.kt
...
private lateinit var styleBar: StyleBar
private lateinit var richEditText: RichEditText
...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
...
styleBar = findViewById(R.id.styleBar)
richEditText = findViewById(R.id.richEditText)
richEditText.setStyleBar(styleBar) // Set StyleBar to EditText
styleBar.setEditText(richEditText) // Set EditText to StyleBar
val html = richEditText.getHtml() // Get formatted html string
...
richEditText.setHtml(html) // Set formatted html string
}
...
For rendering you can use the RichTextView
class:
Add it in your XML
:
<com.easyapps.richeditorlib.widgets.RichTextView
android:id="@+id/richTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Set the html
string content:
val richTextView: RichTextView = findViewById(R.id.richTextView)
richTextView.setHtml(html) // Set formatted html string
If you have any suggestions or found anything, whatever should have an impact on code performance or if you want to provide some improvements, please feel free to open an issue or to contact: [email protected]. Additionally, for specific questions, you can refer to the original library and take a look to some comments in the source code or contact the owner (chinalwb) of the library.
This library runs under Apache-2.0 License for more information please refer to the original library.