Skip to content

Crash on Android 9 (API 28): Failed to resolve textColorLink attribute when inflating DialogTitle #35

@azizutku

Description

@azizutku

Description

On Android 9 (API 28), when an AlertDialog is displayed, the app crashes with an UnsupportedOperationException when trying to inflate internal dialog widgets like DialogTitle.

Stack Trace

Fatal Exception: android.view.InflateException: Binary XML file line #26: Binary XML file line #44: Error inflating class com.android.internal.widget.DialogTitle
Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class com.android.internal.widget.DialogTitle
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x2/d=0x101009b a=1}
    at android.content.res.TypedArray.getColorStateList(TypedArray.java:580)
    at android.widget.TextView.readTextAppearance(TextView.java:3753)
    at android.widget.TextView.<init>(TextView.java:1005)
    at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:115)
    at androidx.appcompat.widget.DialogTitle.<init>(DialogTitle.java)
    at androidx.appcompat.app.ViewPumpAppCompatDelegate.createDialogWidgetView(ViewPumpAppCompatDelegate.java:186)

Root Cause

The TypedValue{t=0x2/d=0x101009b a=1} indicates a failed theme attribute reference:

  • t=0x2 = TYPE_REFERENCE
  • d=0x101009b = android:textColorLink

In ViewPumpAppCompatDelegate.createDialogWidgetView(), dialog widgets are instantiated with createWrappedContext(), which returns ViewPump's wrapped base context (the activity context).

However, this context does not include the dialog's theme. When AlertDialog opens, Android creates a specially-themed context containing dialog-specific attributes like textColorLink, textAppearance, etc. This themed context is passed as the context parameter to createView().

DialogTitle extends AppCompatTextView, which reads text appearance attributes during construction. Since android:textColorLink is defined as a theme attribute reference (?attr/textColorLink), it fails to resolve when the dialog theme is missing from the context.

Environment

  • ViewPump version: 4.0.14
  • Android version: 9 (API 28)
  • Reproducible on both emulator and physical devices

Proposed Solution

Pass the inflationContext (which contains the dialog's theme) to createDialogWidgetView() and create a ContextThemeWrapper that combines ViewPump's wrapped context with the dialog's theme:

val themedSafeContext = android.view.ContextThemeWrapper(
    /* base = */ createWrappedContext(),
    /* theme = */ inflationContext.theme
)
  "com.android.internal.widget.DialogTitle" ->
-     DialogTitle(createWrappedContext(), attrs)
+     DialogTitle(themedSafeContext, attrs)

This preserves ViewPump's wrapped context functionality while ensuring dialog theme attributes can be resolved.

We have a working fix and can submit a PR if you'd like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions