In my opinion, the best thing about Android TV is that it is the same Android we love on our phones and tablets, with just one big restriction — there’s no touchscreen.
This means that a lot of code can be shared if you have a regular mobile app next to your TV app, just make sure the user can navigate on the screen with the remote or controller.
With this restriction comes the worst part too: in order to make the UI navigatable, you have to keep track of user focus — which button, field, tab, etc. the user has currently selected at any time.
This can be easy in a layout with 2 buttons, but it can be quite a task when you have auto-hiding tabs on the top, a hidden drawer on the left, multiple rows and columns of different type of items in the center.
You have to keep track of what should be focusable and what should not, make sure the direction of navigation is logical, and maybe even change the visibility of elements based on where the user is. So to sum it all up, there’s a lot that can go wrong.
Luckily, Google offers some help in this matter. The Leanback library consists of UI elements, fragments and services which do a lot for you if you want to make something similar to the Leanback showcase app.
For us, the two most important classes it contains are the RowsSupportFragment and VerticalGridSupportFragment.
The former can display a vertical list of horizontal rows, the latter an entire grid of items.
Both of these fragments have an inner RecyclerView, on top of which you have to plug an ArrayObjectAdapter and Presenter (or PresenterSelector, if you have multiple item types).
Leanback works perfectly, if you do things the same as in the showcase app. But if you want to do something more special, you might run into limitations.
In the coming sections I will write about my frustrations and problems I had to face while working with Android TV, so maybe I can help if you if you are in the same place as I was.