Skip to content

Commit b13922c

Browse files
committed
Add backgroundColor for View
1 parent b427c6a commit b13922c

File tree

1 file changed

+9
-0
lines changed
  • omegatypes/src/main/java/com/omega_r/libs/omegatypes

1 file changed

+9
-0
lines changed

omegatypes/src/main/java/com/omega_r/libs/omegatypes/Color.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package com.omega_r.libs.omegatypes
33
import android.content.Context
44
import android.content.res.ColorStateList
55
import android.content.res.Resources
6+
import android.graphics.drawable.ColorDrawable
67
import android.os.Build
78
import android.util.SparseIntArray
89
import android.util.TypedValue
10+
import android.view.View
911
import android.widget.TextView
1012
import java.io.Serializable
1113
import java.util.*
@@ -179,4 +181,11 @@ var TextView.linkTextColor: Color
179181
get() = Color.fromColorList(linkTextColors)
180182
set(value) {
181183
setLinkTextColor(value.getColorStateList(context))
184+
}
185+
186+
var View.backgroundColor: Color?
187+
get() = (background as? ColorDrawable)?.color?.let { Color.fromInt(it) }
188+
set(value) {
189+
value?.let { setBackgroundColor(it.getColorInt(context)) }
190+
?: setBackgroundDrawable(null)
182191
}

0 commit comments

Comments
 (0)