material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.29k stars 3.06k forks source link

[TabLayout] setHeight(or setSize) for TabItem's BadgeDrawable ? #797

Open lutics opened 4 years ago

lutics commented 4 years ago

Hello

How can I set height(or size) for BadgeDrawable in TabLayout ?

        TabLayoutMediator(view.tabLayout, view.viewPager, TabLayoutMediator.TabConfigurationStrategy { tab, position ->
            tab.orCreateBadge.apply {
                backgroundColor = Color.parseColor("#db635d")
                horizontalOffset = -10
            }
            tab.text = when (position) {
                0 -> "주문 내역"
                1 -> "받은 선물"
                else -> null
            }
        }).attach()

expected

Screen Shot 2019-11-28 at 12 02 05 PM

but I've got

Screenshot_2019-11-28-14-22-47

wcshi commented 4 years ago

Hi @lutics configuring the badge size is currently not supported because our designers want to ensure that the badge is legible when a number is displayed. Do you have plans to display a number or will this be icon only?

lutics commented 4 years ago

As I left my company, I had no connection with this issue. So close the issue

Kxtreme commented 4 years ago

I don't know if I came on time but I found a simple patch to make it bigger, the idea is attach it and then clear its number I tested with 1.3.0:alpha02 here is a kotlin example:

    private fun addBadgeNotificationToView(
        v: View,
        parent: FrameLayout,
        verticalOffset: Int = 0,
        horizontalOffset: Int = 0): BadgeDrawable {
        val badge = BadgeDrawable.create(this);
        v.viewTreeObserver.addOnGlobalLayoutListener(object: ViewTreeObserver.OnGlobalLayoutListener {
            @Override
            override fun onGlobalLayout() {

                badge.verticalOffset = verticalOffset;
                badge.horizontalOffset = horizontalOffset;
                badge.number = 0

                BadgeUtils.attachBadgeDrawable(
                    badge,
                    v,
                   parent
                );
                badge.clearNumber()
                v.viewTreeObserver.removeOnGlobalLayoutListener(this);
            }
        })

        return badge
    }
JorgeMucientes commented 3 years ago

Hi!

I ended up here because I'm looking for a way to make the badge bigger but apparently it's not supported or haven't found how can this be achieved.

For accessibility reasons when the user selects to display the font big/large from device settings the number inside the badge is not displayed very nicely. It would be great to be able to scale the badge accordingly or set some kind of minimum padding. For example checkout the gmail badge when font is scaled:

(tested in Samsung J7) Screenshot 2021-02-09 at 10 23 44

wcshi commented 3 years ago

@JorgeMucientes are you observing badge text being cut off when Font Size is set to Largest?

I am not able to reproduce the gmail badge bug in your screenshot.

JorgeMucientes commented 3 years ago

Hi! The worst case scenario it's the one I showed in the previous screenshot. Note that not all devices support such a large font size as Samsung devices (Samsung J7 is the device used in the screenshots). I've also tested Pixel devices using android stock, and the font can't be set as large as in Samsung devices. It really depends on the OEM custom software. In general, what I've seen for Samsung is that some numbers display a slight cut off like the number 7 you see in the previous screenshot. But in most cases what happens is there is 0 padding between the number and the badge border but there is no visible cut off. Check some more examples:

Screenshot 2021-02-23 at 08 53 59

Screenshot 2021-02-23 at 09 04 09

wcshi commented 3 years ago

Thank you for reporting this issue, could you please send feedback to Gmail (there should be an option in the app) as well?

JorgeMucientes commented 3 years ago

Yes no problem! reported to the gmail team as well linking to this github issue.

Let me know if you need any further info!

JorgeMucientes commented 2 years ago

Hey @wcshi! Friendly ping. Can we close this issue now?

OtreblaSetroc commented 10 months ago

Hi Guys! @JorgeMucientes Do you have any updates? I'm facing a similar Issue, the number of badge is cutting off when I increase the font size.