AppCompat theme for Leanback
Asked Answered
I

2

10

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.

Immiscible answered 18/6, 2018 at 6:24 Comment(0)
N
16

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.

Nuke answered 5/7, 2018 at 6:41 Comment(0)
G
7

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.

Gout answered 6/5, 2019 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.