参考 https://github.com/TMLAndroid/FillBlankDemo
- 添加依赖
implementation 'com.cnting:fillblankview:version'
- 布局中添加
<com.cnting.fillblankview.FillBlankView
android:layout_width="match_parent"
app:fill_text="A group of ____(sheep) are eating grass and ____(leaf) in front of the farm."
app:fill_split="____"
app:underline_focus_color="@android:color/holo_red_dark"
app:underline_unfocus_color="@android:color/holo_blue_dark"
app:underline_fixed_width="true"
android:id="@+id/fillBlankView1"
app:underline_fixed_width_size="100dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="16sp"/>
</com.cnting.fillblankview.FillBlankView>
在布局中设置
app:underline_fixed_width="true"
app:underline_fixed_width_size="100dp"
调用FillBlankTagUtil.blankToHtml(rightAnswers)
转化成html
private fun init2() {
val answer1 = FillBlankTagUtil.blankToHtml(listOf("sheep"))
val answer2 = FillBlankTagUtil.blankToHtml(listOf("leaves"))
val content =
"A group of $answer1(sheep) are eating grass and $answer2 (leaf) in front of the farm."
fillBlankView2.setFillContent(content, "")
}
调用FillBlankTagUtil.imageToHtml(R.mipmap.ic_launcher)
转化成html
private fun init3() {
val image = FillBlankTagUtil.imageToHtml(R.mipmap.ic_launcher)
val content =
"A group of ____ are eating grass and ____ (leaf) in front of the farm.$image"
fillBlankView3.setFillContent(content, "____")
}
调用FillBlankTagUtil.blankToHtml(rightAnswers:List<String>,userAnswer:String,isRight:Boolean?)
转化成html
private fun init4() {
val answer1 = FillBlankTagUtil.blankToHtml(listOf("sheep", "a sheep"), "sheep")
val answer2 = FillBlankTagUtil.blankToHtml(listOf("leaves", "leaffff"), "leafs")
val content =
"A group of $answer1(sheep) are eating grass and $answer2 (leaf) in front of the farm."
fillBlankView4.setFillContent(content, "")
fillBlankView4.showAnswerResult(true)
fillBlankView4.isEnabled = false
}