question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Chip] Chips are blinking in ChipGroup with custom font

See original GitHub issue

Description: I’m trying to update all Chips in ChipGroup but they are blinking for a short time.

Gif example

Expected behavior: Chips update without blinking.

Source code: Chips are created programmatically:

    private fun createChip(context: Context, chipTitle: String): Chip {
        return Chip(context)
            .apply {
                setTextAppearance(R.style.ChipTextStyle)
                text = chipTitle
                isClickable = false
                isFocusable = false
                setChipBackgroundColorResource(R.color.chipColor)
                setTextColor(ContextCompat.getColor(context, R.color.black))
            }
    }

Style with custom font:

    <style name="ChipTextStyle">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">@color/black</item>
        <item name="android:fontFamily">@font/whitney_medium</item>
    </style>

Update method:

    private fun updateAllChips() {
        chipGroup.removeAllViews()
        val chipsTitles = listOf("Tag 1", "Tag 2", "Tag 3", "Tag 4")
        chipsTitles.forEach { title ->
            val chip = createChip(this, title)
            chipGroup.addView(chip)
        }
    }

Full source code: link to repository

Android API version: 28, 27, 23

Material Library version: 1.1.0

Devices: Meizu 16th api 28, emulators (Nexus 5X api 27, Galaxy Nexus api 23)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
DEcSENTcommented, Oct 14, 2019

@ymarian I wouldn’t say it is expected, because when I set custom font manually all works fine:

    private fun createChip(context: Context, chipTitle: String): Chip {
        val customFont = ResourcesCompat.getFont(context, R.font.whitney_medium)
        return Chip(context)
            .apply {
                typeface = customFont
                textSize = 20f
                text = chipTitle
                isClickable = false
                isFocusable = false
                setChipBackgroundColorResource(R.color.chipColor)
                setTextColor(ContextCompat.getColor(context, R.color.black))
            }
    }
0reactions
ryan-mcgoffcommented, Jul 23, 2021

I also encountered the flickering issue in version 1.2.1 when using a custom font, I updated to the latest version 1.4.1, and the flickering is now gone 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change the typeface of Chip view? - android
I load chips programmatically and chip view blinks as it first loads default font, and after that my font. With many chips, it...
Read more >
Android P: Chips and ChipGroup - DigitalOcean
Chips are basically a text displayed in a rounded background. ... This is how the chip looks on the screen: android chips default...
Read more >
How To Change The Typeface Of Chip View - ADocLib
Chips allow users to enter information make selections filter content or trigger actions. ... [Chip] Chips are blinking in ChipGroup with custom font...
Read more >
ChipGroup - Android Developers
A ChipGroup is used to hold multiple Chip s. By default, the chips are reflowed across multiple lines. Set the app:singleLine attribute to ......
Read more >
[Solved]-Animate Chip checking in Material Chipgroup (Android)
For this option add the following custom Chip class (Kotlin) to your ... You can observe a flickering of adjacent chips during the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found