Skip to content

Instantly share code, notes, and snippets.

@ademar111190
Created June 12, 2019 20:31
Show Gist options
  • Save ademar111190/795873cc62851adb1259e5f5b6d44bc4 to your computer and use it in GitHub Desktop.
Save ademar111190/795873cc62851adb1259e5f5b6d44bc4 to your computer and use it in GitHub Desktop.
Step 6, the init block.
...
import ademar.bnindicator.R.styleable.*
import androidx.appcompat.content.res.AppCompatResources.getDrawable
class BottomNavigationViewIndicator
...
private val targetId: Int
private val backgroundDrawable: Drawable
init {
if (attrs == null) {
targetId = NO_ID
backgroundDrawable = ColorDrawable(Color.TRANSPARENT)
} else {
with(context.obtainStyledAttributes(attrs, BottomNavigationViewIndicator)) {
targetId = getResourceId(BottomNavigationViewIndicator_targetBottomNavigation, NO_ID)
val clipableId = getResourceId(BottomNavigationViewIndicator_clipableBackground, NO_ID)
backgroundDrawable = if (clipableId != NO_ID) {
getDrawable(context, clipableId) ?: ColorDrawable(Color.TRANSPARENT)
} else {
ColorDrawable(getColor(BottomNavigationViewIndicator_clipableBackground, Color.TRANSPARENT))
}
recycle()
}
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment