@@ -10,6 +10,8 @@ import android.text.style.UnderlineSpan
1010import android.view.View
1111import android.widget.TextView
1212import androidx.annotation.ColorRes
13+ import androidx.core.content.ContextCompat
14+ import androidx.core.widget.TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds
1315import com.omega_r.libs.extensions.context.getCompatColor
1416
1517fun 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+
153159var 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+
168178var 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+
175189var 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+
191209var 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+
206228var 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+
221247fun 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