Skip to content

Commit b78a6b9

Browse files
committed
Add Textview.setDrawableBottom Resourcse
1 parent 6dd2eab commit b78a6b9

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensionslib/src/main/java/com/omega_r/libs/extensions/view/TextViewExtensions.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import android.text.style.UnderlineSpan
1010
import android.view.View
1111
import android.widget.TextView
1212
import androidx.annotation.ColorRes
13+
import androidx.core.content.ContextCompat
14+
import androidx.core.widget.TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds
1315
import com.omega_r.libs.extensions.context.getCompatColor
1416

1517
fun TextView.addTextListener(
@@ -150,6 +152,10 @@ var TextView.drawableLeft: Drawable?
150152
setCompoundDrawablesWithIntrinsicBounds(value, drawables[1], drawables[2], drawables[3])
151153
}
152154

155+
fun TextView.setDrawableLeft(drawableRes: Int) {
156+
drawableLeft = ContextCompat.getDrawable(context, drawableRes)
157+
}
158+
153159
var TextView.drawableStart: Drawable?
154160
get() = (if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) compoundDrawablesRelative[0] else compoundDrawables[0])
155161
set(value) {
@@ -165,13 +171,21 @@ var TextView.drawableStart: Drawable?
165171
}
166172
}
167173

174+
fun TextView.setDrawableStart(drawableRes: Int) {
175+
drawableStart = ContextCompat.getDrawable(context, drawableRes)
176+
}
177+
168178
var TextView.drawableRight: Drawable?
169179
get() = compoundDrawables[2]
170180
set(value) {
171181
val drawables = compoundDrawables
172182
setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], value, drawables[3])
173183
}
174184

185+
fun TextView.setDrawableRight(drawableRes: Int) {
186+
drawableRight = ContextCompat.getDrawable(context, drawableRes)
187+
}
188+
175189
var TextView.drawableEnd: Drawable?
176190
get() = (if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) compoundDrawablesRelative[2] else compoundDrawables[2])
177191
set(value) {
@@ -188,6 +202,10 @@ var TextView.drawableEnd: Drawable?
188202
}
189203
}
190204

205+
fun TextView.setDrawableEnd(drawableRes: Int) {
206+
drawableEnd = ContextCompat.getDrawable(context, drawableRes)
207+
}
208+
191209
var TextView.drawableTop: Drawable?
192210
get() = (if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) compoundDrawablesRelative[1] else compoundDrawables[1])
193211
set(value) {
@@ -203,6 +221,10 @@ var TextView.drawableTop: Drawable?
203221
}
204222
}
205223

224+
fun TextView.setDrawableTop(drawableRes: Int) {
225+
drawableTop = ContextCompat.getDrawable(context, drawableRes)
226+
}
227+
206228
var TextView.drawableBottom: Drawable?
207229
get() = (if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) compoundDrawablesRelative[3] else compoundDrawables[3])
208230
set(value) {
@@ -218,6 +240,10 @@ var TextView.drawableBottom: Drawable?
218240
}
219241
}
220242

243+
fun TextView.setDrawableBottom(drawableRes: Int) {
244+
drawableBottom = ContextCompat.getDrawable(context, drawableRes)
245+
}
246+
221247
fun TextView.removeCompoundDrawables() {
222248
setCompoundDrawables(null, null, null, null)
223249
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) setCompoundDrawablesRelative(null, null, null, null)

0 commit comments

Comments
 (0)