{"record":{"id":"5a06f721893991e1","repo":"material-components/material-components-android","slug":"searchbar-does-not-support-title-use-hint-or-text","errorCode":null,"errorMessage":"SearchBar does not support title. Use hint or text instead.","messagePattern":"SearchBar does not support title\\. Use hint or text instead\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/search/SearchBar.java","lineNumber":270,"sourceCode":"    textView = findViewById(R.id.open_search_bar_text_view);\n    placeholderTextView = findViewById(R.id.open_search_bar_placeholder_text_view);\n    textViewContainer = findViewById(R.id.open_search_bar_text_view_container);\n\n    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;","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/search/SearchBar.java#L252-L288","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove app:title from the SearchBar element and set the placeholder with app:hint or setHint(...) / setSearchBarText.","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.","Audit layouts for app:title=\"@null\" too — any non-null value, even empty-string resources, throws."],"exampleFix":"<!-- before -->\n<com.google.android.material.search.SearchBar\n    app:title=\"My App\" ... />\n\n<!-- after -->\n<com.google.android.material.search.SearchBar\n    app:hint=\"Search\" ... />","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["When migrating Toolbar layouts to SearchBar, diff the XML and delete title/subtitle attrs.","Use app:hint and setHint() for SearchBar text.","Add a lint/CI grep for 'app:title' and 'app:subtitle' inside SearchBar elements."],"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"}