# TitleViewAdapter

Artifact: [androidx.leanback:leanback](https://developer.android.com/jetpack/androidx/releases/leanback) [View Source](https://cs.android.com/search?q=file:androidx/leanback/widget/TitleViewAdapter.java+class:androidx.leanback.widget.TitleViewAdapter) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

*** ** * ** ***


```
public abstract class TitleViewAdapter
```

<br />

*** ** * ** ***

This class allows a customized widget class to implement `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter.Provider` and expose `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter` methods to containing fragment (e.g. BrowseFragment or DetailsFragment). The title view must have a search orb view (`https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#getSearchAffordanceView()` aligned to start and can typically have a branding Drawable and or title text aligned to end. The branding part is fully open to customization: not necessary to be a drawable or text.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter.Provider` Interface to be implemented by a customized widget class to implement `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter`. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#BRANDING_VIEW_VISIBLE() = 2` |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#FULL_VIEW_VISIBLE() = 6` |
| `static final int` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#SEARCH_VIEW_VISIBLE() = 4` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#TitleViewAdapter()()` |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#getBadgeDrawable()()` Returns the badge drawable. |
| `https://developer.android.com/reference/androidx/leanback/widget/SearchOrbView.Colors` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#getSearchAffordanceColors()()` Returns the `https://developer.android.com/reference/androidx/leanback/widget/SearchOrbView.Colors` used to draw the search affordance. |
| `abstract https://developer.android.com/reference/android/view/View.html` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#getSearchAffordanceView()()` Returns the view for the search affordance. |
| `https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#getTitle()()` Returns the title text. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#setAnimationEnabled(boolean)(boolean enable)` Enables or disables any view animations. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#setBadgeDrawable(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable.html drawable)` Sets the badge drawable. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#setOnSearchClickedListener(android.view.View.OnClickListener)(https://developer.android.com/reference/android/view/View.OnClickListener.html listener)` Sets a click listener for the search affordance view. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#setSearchAffordanceColors(androidx.leanback.widget.SearchOrbView.Colors)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/widget/SearchOrbView.Colors colors)` Sets the `https://developer.android.com/reference/androidx/leanback/widget/SearchOrbView.Colors` used to draw the search affordance. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#setTitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence.html titleText)` Sets the title text. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#updateComponentsVisibility(int)(int flags)` Based on the flag, it updates the visibility of the individual components - Branding views (badge drawable and/or title) and search affordance view. |

## Constants

### BRANDING_VIEW_VISIBLE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int BRANDING_VIEW_VISIBLE = 2
```

### FULL_VIEW_VISIBLE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int FULL_VIEW_VISIBLE = 6
```

### SEARCH_VIEW_VISIBLE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public static final int SEARCH_VIEW_VISIBLE = 4
```

## Public constructors

### TitleViewAdapter

Added in 1.1.0

```
public TitleViewAdapter()
```

## Public methods

### getBadgeDrawable

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public Drawable getBadgeDrawable()
```

Returns the badge drawable.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | The badge drawable. |

### getSearchAffordanceColors

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public SearchOrbView.Colors getSearchAffordanceColors()
```

Returns the `https://developer.android.com/reference/androidx/leanback/widget/SearchOrbView.Colors` used to draw the search affordance.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/leanback/widget/SearchOrbView.Colors` | Colors used to draw search affordance. |

### getSearchAffordanceView

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public abstract View getSearchAffordanceView()
```

Returns the view for the search affordance.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/view/View.html` | The view for search affordance. |

### getTitle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public CharSequence getTitle()
```

Returns the title text.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence.html` | The title text. |

### setAnimationEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setAnimationEnabled(boolean enable)
```

Enables or disables any view animations. This method is called to save CPU cycle for example stop search view breathing animation when containing fragment is paused.

| Parameters |
|---|---|
| `boolean enable` | True to enable animation, false otherwise. |

### setBadgeDrawable

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setBadgeDrawable(Drawable drawable)
```

Sets the badge drawable. If non-null, the drawable is displayed instead of the title text.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html drawable` | The badge drawable to set on title view. |

### setOnSearchClickedListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setOnSearchClickedListener(View.OnClickListener listener)
```

Sets a click listener for the search affordance view.

The presence of a listener will change the visibility of the search affordance in the fragment title. When set to non-null, the title will contain an element that a user may click to begin a search.

The listener's `https://developer.android.com/reference/android/view/View.OnClickListener.html#onClick(android.view.View)` method will be invoked when the user clicks on the search element.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.OnClickListener.html listener` | The listener to call when the search element is clicked. |

### setSearchAffordanceColors

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setSearchAffordanceColors(@NonNull SearchOrbView.Colors colors)
```

Sets the `https://developer.android.com/reference/androidx/leanback/widget/SearchOrbView.Colors` used to draw the search affordance.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/widget/SearchOrbView.Colors colors` | Colors used to draw search affordance. |

### setTitle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void setTitle(CharSequence titleText)
```

Sets the title text.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence.html titleText` | The text to set as title. |

### updateComponentsVisibility

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void updateComponentsVisibility(int flags)
```

Based on the flag, it updates the visibility of the individual components - Branding views (badge drawable and/or title) and search affordance view.

| Parameters |
|---|---|
| `int flags` | integer representing the visibility of TitleView components. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#BRANDING_VIEW_VISIBLE()` |   |
| `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#SEARCH_VIEW_VISIBLE()` |   |
| `https://developer.android.com/reference/androidx/leanback/widget/TitleViewAdapter#FULL_VIEW_VISIBLE()` |   |