Skip to content

Commit 1d0d7fe

Browse files
committed
Add includeTextSpace
1 parent bd08c43 commit 1d0d7fe

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
app:startTextFont="sans-serif-thin"
1919
app:endText="@string/app_name"
2020
app:endTextStyle="bold|underline"
21+
app:includeTextSpace="true"
2122
app:layout_constraintBottom_toBottomOf="parent"
2223
app:layout_constraintLeft_toLeftOf="parent"
2324
app:layout_constraintRight_toRightOf="parent"

omegaviwslibs/src/main/java/com/omega_r/libs/views/OmegaTextView.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ open class OmegaTextView @JvmOverloads constructor(
3636
var endText: Text? = null
3737
set(value) {
3838
field = value
39-
if (initData) {
40-
updateAllText()
41-
}
39+
updateAllText()
40+
41+
}
42+
43+
var spaceText: Text? = null
44+
set(value) {
45+
field = value
46+
updateAllText()
4247
}
4348

4449
private val startTextStyle = Style()
@@ -83,6 +88,11 @@ open class OmegaTextView @JvmOverloads constructor(
8388
R.styleable.OmegaTextView_endTextFont -> {
8489
endTextStyle.fontFamily = a.getString(attr)
8590
}
91+
R.styleable.OmegaTextView_includeTextSpace -> {
92+
if (a.getBoolean(attr, false)) {
93+
spaceText = Text.from(" ")
94+
}
95+
}
8696

8797
}
8898
}
@@ -103,8 +113,8 @@ open class OmegaTextView @JvmOverloads constructor(
103113

104114
private fun updateAllText(force: Boolean = false) {
105115
if (initData || force) {
106-
val allText = (startText + startTextStyle) + text + (endText + endTextStyle)
107-
super.setText(allText?.getCharSequence(context), BufferType.SPANNABLE)
116+
val allText = (startText + startTextStyle) + spaceText + text + spaceText + (endText + endTextStyle)
117+
super.setText(allText?.getCharSequence(context), BufferType.NORMAL)
108118
}
109119
}
110120

omegaviwslibs/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<attr name="startTextFont" format="string"/>
2828
<attr name="endTextFont" format="string"/>
2929

30+
<attr name="includeTextSpace" format="boolean"/>
31+
3032
</declare-styleable>
3133

3234
</resources>

0 commit comments

Comments
 (0)