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.
AppCompatTextView is an AppCompat widget that can only be used with a Theme.
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.
// 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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With