Low Contrast Between Text and Background

Id LowContrastBetweenTextandBackground
Summary Insufficient contrast impairs text legibility, especially under bright light
Severity Warning
Category Visual Accessibility
Affects Resource files and Kotlin and Java files
Implementation Custom lint rule – analyzes text and background color combinations set statically

Symptom

Elements have insufficient contrast between foreground and background, making them difficult to distinguish.

Rationale

Low Contrast Between Text and Background reduces visibility for users with low vision or color vision deficiencies and can make critical information harder to perceive.

Examples

XML Layout Example

<!-- Insufficient contrast ratio -->
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Warning message"
    android:textColor="@color/text_low_contrast"
    android:background="@android:color/white" />

Kotlin Code Example

class MainActivity : AppCompatActivity() {

    private fun setLowContrastColors() {
        val textView = findViewById<TextView>(R.id.message)
        // Programmatically setting low contrast colors
        textView.setTextColor(Color.parseColor("#999999")) // Light gray on white
        textView.setBackgroundColor(Color.WHITE)
    }
}

GitHub issues under this tag