-1

I just notice that my Android app, when I run it on Android TV with leanback intent, that it doesn't show a sandwich button for the menu items.

This is missing, and everthing else like the title:
enter image description here

What is the suggested alternative? Is it possible to listen to a button on the remote control and make the menu items visible?

1 Answers1

2

Incase you are looking for tab based navigation, The Leanback templates provide side navigation in the browse experience, which works well for many apps. If you need tab navigation (typically displayed horizontally across the top of the app), you can instead use Leanback Tabs.

Add the library to your project:

implementation "androidx.leanback:leanback-tab:$version"

Sample code

val leanbackTabLayout = findViewById<LeanbackTabLayout>(R.id.tab_layout)
val leanbackViewPager = findViewById<LeanbackViewPager>(R.id.view_pager)

leanbackViewPager.setAdapter(adapter)
leanbackTabLayout.setupWithViewPager(leanbackViewPager)

Then implement tabs using LeanbackTabLayout and LeanbackViewPager by following the existing ViewPager guide. Note that LeanbackViewPager is based on ViewPager, not ViewPager2.

Note that only themes that are derived from Theme.AppCompat are supported.

enter image description here

Mayuri Khinvasara
  • 1,437
  • 1
  • 16
  • 12
  • Are these the same tabs like in the leanback vesion of Google Play? –  Dec 29 '20 at 07:14
  • Can you paste a pic of what UI are you looking at ? This navigation was launched in Google IO 2020. – Mayuri Khinvasara Dec 29 '20 at 07:17
  • 1
    right top example here https://ithelp.ithome.com.tw/articles/10249859 , but I think the screenshot is already outdated, there were some changes a few weeks ago. But anyway thanks, got it! Might try something in this direction. –  Dec 29 '20 at 07:22
  • Thanks. Incase this approach solves your problem, can you please accept the answer. – Mayuri Khinvasara Dec 30 '20 at 05:43
  • Your answer is only half an answer. It doesn't answer "make the menu items visible". The non-TV app bar also shows, upon pressing the sandwich button, what has been added during the call-back onCreateOptionsMenu( Menu) and serves onOptionsItemSelected( MenuItem) events. I am not yet sure how I should go about this problem. –  Dec 30 '20 at 11:24