| Id | UnlabeledToolbarNavigationControls |
| Summary | Toolbar buttons lack descriptive text, leaving their function unclear to assistive tools |
| Severity | Warning |
| Category | Assistive Technologies / Content Descriptions |
| Affects | Resource files and Kotlin and Java files |
| Implementation |
Custom lint rule
- detect Toolbar elements with app:navigationIcon but
missing app:navigationContentDescription attribute
|
| Tests | Source Code |
Toolbar navigation icons lack the
app:navigationContentDescription attribute, preventing
assistive technologies from providing meaningful information about the
navigation action's purpose or destination.
Without navigation content descriptions, assistive technology users cannot understand what the toolbar navigation icon does (e.g., "go back," "open menu," "go up"), creating barriers to navigation and preventing users from understanding available navigation options or their expected behavior
<!-- Back navigation without description -->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:navigationIcon="@drawable/ic_arrow_back" />
<!-- Missing: app:navigationContentDescription="Navigate back" -->
class DetailActivity : AppCompatActivity() {
private fun setupToolbar() {
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
// The developer sets a CUSTOM icon, not the default "up" arrow
toolbar.navigationIcon = ContextCompat.getDrawable(this, R.drawable.ic_close)
// Missing: toolbar.navigationContentDescription = "Close details"
toolbar.setNavigationOnClickListener {
finish()
}
}
}