Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompat theme for Leanback

I opened my old Android TV app project and tried to update the dependencies. I then updated the appcompat libraries to 27.1.1. I opened the leanback fragments and Android Studio warned me the BrowseFragment is deprecated and I should use BaseSupportFragment instead. Same case for other leanback fragments. I then changed all the fragment to AppCompat version (except for LeanbackSettingsFragment as there was no AppCompat version provided) and then changed my Activities extend AppCompatActivity.

After I made these changes, I built the app but when I launched the app I saw this error in logcat:

Unable to start activity ComponentInfo{net.swiftzer.trainboard.dev/net.swiftzer.trainboard.main.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

The theme I used for the app and activities are all under Theme.Leanback. But I checked the theme is based on platform native theme.

Should I stick with the deprecated leanback fragment classes or the leanback library do provides AppCompat themes? The leanback library is like a half-baked one. I saw the leanback library do provides an AppCompat version of fragments last year but no sample projects was using them. Now they marked the fragment classes extended from android.app.Fragment as deprecated but they didn't provide proper way to migrate.

like image 663
Eric Li Avatar asked Jun 18 '18 06:06

Eric Li


People also ask

Is an AppCompat widget that can only be used with a theme AppCompat?

AppCompatTextView is an AppCompat widget that can only be used with a Theme.

What is Leanback?

The leanback library provides a templated UI so developers can focus on the important parts of their app. When using leanback, content is shown in rows. Leanback supplies a rectangular card view, ImageCardView, to easily display content. The card size scales when selected and has shadows to accent the content.

What is leanback UI?

// leanback-preference is an add-on that provides a settings UI for TV apps. implementation "androidx.leanback:leanback-preference:$leanback_version" // leanback-paging is an add-on that simplifies adding paging support to a RecyclerView Adapter.


2 Answers

You can't use Theme.Leanback for Activities extending AppCompatActivity. For using support fragments you can't extend the activity with android.app.Activity either. For using support fragments extend your activity with android.support.v4.app.FragmentActivity.

like image 145
Rohit P Soman Avatar answered Sep 21 '22 17:09

Rohit P Soman


You are not allowed to use AppCompat theme for Android TV with Leanback library. You should extend your BaseActivity of the FragmentActivity to benefit from the Support Components.

like image 35
Majid Khosravi Avatar answered Sep 19 '22 17:09

Majid Khosravi