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

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

Error message

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

What it means

SearchBar.validateAttributes() throws UnsupportedOperationException when the XML declares app:title. SearchBar renders a placeholder TextView, not a Toolbar title, so the title attribute is meaningless and rejected at inflation time to prevent silent no-ops. Use the placeholder/hint mechanism instead.

Source

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

    textView = findViewById(R.id.open_search_bar_text_view);
    placeholderTextView = findViewById(R.id.open_search_bar_placeholder_text_view);
    textViewContainer = findViewById(R.id.open_search_bar_text_view_container);

    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;

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Remove app:title from the SearchBar element and set the placeholder with app:hint or setHint(...) / setSearchBarText.
  2. If you need title + search together, put the SearchBar in an AppBarLayout next to a collapsed-title toolbar or use SearchBar's navigation/placeholder APIs.
  3. Audit layouts for app:title="@null" too — any non-null value, even empty-string resources, throws.

Example fix

<!-- before -->
<com.google.android.material.search.SearchBar
    app:title="My App" ... />

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

Strategy: validation

Prevention

When it happens

Trigger: Declaring app:title (or app:title="...") on a com.google.android.material.search.SearchBar element in a layout; commonly copied from a MaterialToolbar/Toolbar layout.

Common situations: Migrating a Toolbar layout to SearchBar and leaving app:title behind; copy-pasting Toolbar XML; tools: attributes are fine but app:title triggers the crash at inflate.

Related errors


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