Unlabeled Toolbar Navigation Controls

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

Symptom

Toolbar navigation icons lack the app:navigationContentDescription attribute, preventing assistive technologies from providing meaningful information about the navigation action's purpose or destination.

Rationale

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

Examples

XML Layout Example

<!-- 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" -->

Kotlin Code Example

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()
        }
    }
}

GitHub issues under this tag