Skip to content

[BottomNavigation] Disable item view clipping #1107

Open
@jarrodrobins

Description

@jarrodrobins

Is your feature request related to a problem? Please describe.
Currently, item icons are clipped to 24dp x 24dp. I'd like the flexibility to override this to allow for wider icons.

While it is possible to change the overall size of the icons using itemIconSize, this is not ideal as it will scale smaller image assets up to fit that size - ie, it's not a maximum size, it's the actual size.

Currently, my working solution is to iterate through all the bottom bar item views, disable clipping for children, and changing the scale type to CENTER (I'm guessing the default is FIT_XY?).

        val menuView = bottomNavigation.getChildAt(0) as BottomNavigationMenuView
        for (i in 0 until menuView.childCount) {
            val itemView = menuView.getChildAt(i) as FrameLayout
            val iconView = itemView
                .findViewById<AppCompatImageView>(com.google.android.material.R.id.icon)
            itemView.clipChildren = false
            iconView.scaleType = ImageView.ScaleType.CENTER
        }

This allows me to have a wider icon than 24dp without getting clipped.

Describe the solution you'd like
Because I'm really doing two things here, I think it makes sense to expose these two methods on BottomNavigationView via exposing BottomNavigationItemView's clipChildren and the icon view's scaleType. This could be via BottomNavigationView methods -

itemClipChildren and itemIconScaleType

mirroring similar naming of eg itemIconTint and itemTextColor

Describe alternatives you've considered
This could be condensed down to one method but that would reduce flexibility that others may need outside my particular use case.

Additional context
image

Notice the sport icon here - it's a little wider than the other icons.

If you like the idea, I'm happy to write the pull request myself but wanted to raise it in case other ideas are suggested or changes requested.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions