{"record":{"id":"47c5dcbeb3d50631","repo":"material-components/material-components-android","slug":"searchbar-does-not-support-subtitle-use-hint-or-t","errorCode":null,"errorMessage":"SearchBar does not support subtitle. Use hint or text instead.","messagePattern":"SearchBar does not support subtitle\\. Use hint or text instead\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/search/SearchBar.java","lineNumber":274,"sourceCode":"    setElevation(elevation);\n    initTextView(textAppearanceResId, text, hint);\n    initBackground(shapeAppearanceModel, backgroundColor, elevation, strokeWidth, strokeColor);\n  }\n\n  void setPlaceholderText(String string) {\n    placeholderTextView.setText(string);\n  }\n\n  private void validateAttributes(@Nullable AttributeSet attributeSet) {\n    if (attributeSet == null) {\n      return;\n    }\n    if (attributeSet.getAttributeValue(NAMESPACE_APP, \"title\") != null) {\n      throw new UnsupportedOperationException(\n          \"SearchBar does not support title. Use hint or text instead.\");\n    }\n    if (attributeSet.getAttributeValue(NAMESPACE_APP, \"subtitle\") != null) {\n      throw new UnsupportedOperationException(\n          \"SearchBar does not support subtitle. Use hint or text instead.\");\n    }\n  }\n\n  @Nullable\n  AppBarLayout getAppBarLayoutParentIfExists() {\n    ViewParent v = getParent();\n    while (v != null) {\n      if (v instanceof AppBarLayout) {\n        return (AppBarLayout) v;\n      }\n      v = v.getParent();\n    }\n    return null;\n  }\n\n  private void initNavigationIcon() {\n    // If no navigation icon, set up the default one; otherwise, re-set it for tinting if needed.","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/search/SearchBar.java#L256-L292","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove app:subtitle from the SearchBar element and show secondary text via app:hint / setHint().","If a subtitle is a hard requirement, wrap the SearchBar with a Toolbar-based layout instead of attribute reuse.","Search layouts/styles for 'subtitle' on SearchBar elements after any Toolbar-to-SearchBar migration."],"exampleFix":"<!-- before -->\n<com.google.android.material.search.SearchBar\n    app:subtitle=\"3 results\" ... />\n\n<!-- after -->\n<com.google.android.material.search.SearchBar\n    app:hint=\"Search\" ... />","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["SearchBar supports one text line only; plan secondary text outside the widget.","Audit styles applied to SearchBar for inherited Toolbar attributes."],"tags":["android","material-components","searchbar","xml","attributes"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}