material-components/material-components-android · error · UnsupportedOperationException

SearchBar does not support subtitle. Use hint or text instea

Error message

SearchBar does not support subtitle. Use hint or text instead.

What it means

SearchBar.validateAttributes() throws UnsupportedOperationException when the XML declares app:subtitle. SearchBar has no subtitle UI — it shows a single placeholder/hint text — so the attribute is explicitly rejected at inflation to fail fast rather than silently ignoring it.

Source

Thrown at lib/java/com/google/android/material/search/SearchBar.java:274

    setElevation(elevation);
    initTextView(textAppearanceResId, text, hint);
    initBackground(shapeAppearanceModel, backgroundColor, elevation, strokeWidth, strokeColor);
  }

  void setPlaceholderText(String string) {
    placeholderTextView.setText(string);
  }

  private void validateAttributes(@Nullable AttributeSet attributeSet) {
    if (attributeSet == null) {
      return;
    }
    if (attributeSet.getAttributeValue(NAMESPACE_APP, "title") != null) {
      throw new UnsupportedOperationException(
          "SearchBar does not support title. Use hint or text instead.");
    }
    if (attributeSet.getAttributeValue(NAMESPACE_APP, "subtitle") != null) {
      throw new UnsupportedOperationException(
          "SearchBar does not support subtitle. Use hint or text instead.");
    }
  }

  @Nullable
  AppBarLayout getAppBarLayoutParentIfExists() {
    ViewParent v = getParent();
    while (v != null) {
      if (v instanceof AppBarLayout) {
        return (AppBarLayout) v;
      }
      v = v.getParent();
    }
    return null;
  }

  private void initNavigationIcon() {
    // If no navigation icon, set up the default one; otherwise, re-set it for tinting if needed.

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Remove app:subtitle from the SearchBar element and show secondary text via app:hint / setHint().
  2. If a subtitle is a hard requirement, wrap the SearchBar with a Toolbar-based layout instead of attribute reuse.
  3. Search layouts/styles for 'subtitle' on SearchBar elements after any Toolbar-to-SearchBar migration.

Example fix

<!-- before -->
<com.google.android.material.search.SearchBar
    app:subtitle="3 results" ... />

<!-- after -->
<com.google.android.material.search.SearchBar
    app:hint="Search" ... />
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Declaring app:subtitle on a com.google.android.material.search.SearchBar element in a layout, typically carried over from a MaterialToolbar layout that displayed title + subtitle.

Common situations: Converting a MaterialToolbar with title/subtitle pair into a SearchBar; templates or layout snippets that include both attributes; a style applied via SearchBarStyle that sets subtitle.

Related errors


AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14). Data as JSON: /api/errors/47c5dcbeb3d50631. Report an issue: GitHub.