Skip to content

Commit

Permalink
Merge pull request #2797 from bmx666/develop
Browse files Browse the repository at this point in the history
fix getColorStateList for API22 and below
  • Loading branch information
mikepenz committed Aug 15, 2023
2 parents b75d4a7 + fab6ef6 commit 3cf438b
Showing 1 changed file with 11 additions and 4 deletions.
Expand Up @@ -8,6 +8,7 @@ import android.graphics.drawable.Drawable
import android.graphics.drawable.StateListDrawable
import android.util.TypedValue
import androidx.annotation.*
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import com.mikepenz.materialdrawer.R
Expand Down Expand Up @@ -37,10 +38,14 @@ internal fun Context.getSecondaryDrawerIconColor(): ColorStateList {

fun createDrawerItemColorStateList(ctx: Context, @StyleableRes styleableRes: Int): ColorStateList? {
val a = ctx.obtainStyledAttributes(null, R.styleable.MaterialDrawerSliderView, R.attr.materialDrawerStyle, R.style.Widget_MaterialDrawerStyle)
val baseColor = a.getColorStateList(styleableRes)
val baseColorResId = a.getResourceId(styleableRes, -1)
a.recycle()

return baseColor
return if (baseColorResId != -1) {
AppCompatResources.getColorStateList(ctx, baseColorResId)
} else {
null
}
}

@ColorInt
Expand All @@ -66,13 +71,15 @@ internal fun Context.getSelectedColor(): Int {

internal fun Context.getHeaderSelectionTextColor(): ColorStateList {
return resolveStyledHeaderValue {
it.getColorStateList(R.styleable.AccountHeaderView_materialDrawerHeaderSelectionText)!!
val resId = it.getResourceId(R.styleable.AccountHeaderView_materialDrawerHeaderSelectionText, -1)
AppCompatResources.getColorStateList(this, resId)
}
}

internal fun Context.getHeaderSelectionSubTextColor(): ColorStateList {
return resolveStyledHeaderValue {
it.getColorStateList(R.styleable.AccountHeaderView_materialDrawerHeaderSelectionSubtext)!!
val resId = it.getResourceId(R.styleable.AccountHeaderView_materialDrawerHeaderSelectionSubtext, -1)
AppCompatResources.getColorStateList(this, resId)
}
}

Expand Down

0 comments on commit 3cf438b

Please sign in to comment.