How to customize the title view in the VerticalGridFragment [Android TV]

Wilfried Mbouenda Mbogne
ProAndroidDev
Published in
2 min readMar 12, 2018

--

When we develop for Android TV, sometime we need to customize the look and feel of our application. One fragment of Android I found difficult to customize is the VerticalGridFragment.

In this article, we will customize the Title View of the VerticalGridFragment.

Introduction

Before talking about the customization, Let’s introduce the VerticalGridFragment. According to developer.android.com, the VerticalGridFragment is a fragment for creating leanback vertical grids. It Renders a vertical grid of objects given a VerticalGridPresenter and an ObjectAdapter.

Now Let’s imagine we want the title text size to be smaller and have a different color.

Step 1 Create a layout of our custom title view

Step 2 Create a class for our Custom title

Step 3 Create another layout enclosing our previous class

Step 4 Create a customized style for your Activity

Let’s use this style in our Activity.

Step 5 Use the method setTitle and let’s enjoy the magic

Now you can use the method setTitle normaly and This is it.

If you need to do more change, you can modify custom_titleview.xml

Conclusion

So far, we learn about customizing the title view of the VerticalGridFragment in AndroidTV. It was a step by step process

  1. We created a layout resource with the style of Titleview
  2. We created a custom class implementing TitleViewAdapter.Provider inflating the previous layout
  3. We created another layout resource enclosing the previous class
  4. We created a custom style resource referencing the previous layout
  5. We applied the previous style to our Activity in the manifest

If you want to test it yourself, you can get the whole project on github.

Hope you enjoyed this article and until then my friend, may the {code} be with you!

References:

Originally published at Developer Journey.

--

--

Senior Android Engineer, public speaker. Born in Africa, living in Europe. Work hard, play hard, rest hard www.developer-journey.com #HipHopLover,#TvShow addict