Skip to content

[BadgeDrawable] TalkBack not reading badge count when badge is set on toolbar menu item #2429

@nimaiwalsh

Description

@nimaiwalsh

Description: Full description of issue here

  • TalkBack not reading badge count when badge is created for an action menu item on the toolbar and the following is set:
    setContentDescriptionQuantityStringsResource(R.plurals.attachment_count_plural)
  • contentDescription is correct when debugging using getContentDescription

Expected behavior: Screenshots and/or description of expected behavior
TalkBack will read the plural string with quantity

Source code: The code snippet which is causing this issue. Please consider attaching a minimal sample app that reproduces the issue.

@ExperimentalBadgeUtils
/**
 * Creates a [BadgeDrawable] for an action item in the [Toolbar]
 * Run [BadgeDrawable.updateBadgeCount] function to make badge visible with expected count.
 * @param menuItemId @IdRes - action menu item to apply badge
 * @param textColour @AttrRes - badge text color
 * @param textColour @AttrRes - badge text color
 * */
fun Toolbar.createBadge(
    @IdRes menuItemId: Int,
    @AttrRes textColour: Int? = null,
    @AttrRes backgroundColor: Int? = null,
): BadgeDrawable {
    val badge = BadgeDrawable.create(this.context)
    badge.maxCharacterCount = 3
    badge.badgeGravity = BadgeDrawable.TOP_END
    textColour?.let {
        badge.badgeTextColor = it
    }
    backgroundColor?.let {
        badge.backgroundColor = it
    }
    badge.isVisible = false
    badge.setContentDescriptionQuantityStringsResource(R.plurals.attachment_count_plural)
    BadgeUtils.attachBadgeDrawable(badge, this, menuItemId)
    return badge
}

/**
 * Update the count for [BadgeDrawable]
 * @param count - badge count as an [Int]
 * */
fun BadgeDrawable.updateBadgeCount(count: Int) {
    isVisible = count > 0
    number = count
    verticalOffset = 10
    // Offset to prevent clipping
    horizontalOffset = when {
        count > 99 -> 24
        count > 9 -> 12
        else -> 0
    }
}

Android API version: Android API version here
Tested on API 29

Material Library version: Material Android Library version you are using here (e.g., 1.1.0-alpha07)
materialVersion = '1.3.0'

Device: Device on which the bug was encountered here
Emulator Pixel 4, TalkBack

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions