Jaime Guerrero
01/08/2021, 12:44 PM@Test
fun testFragment() {
launchFragmentInContainer<CountryFragment>(themeResId = R.style.AppTheme)
...
}
My style is:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
...
</style>
onCreateOptionsMenu(menu: Menu, inflater: MenuInflater)
in the fragment is not called and the actionbar is hide. If I use R.style.ThemeOverlay_MaterialComponents_Dark_ActionBar
for instance , onCreateOptionsMenu
is called and the actionbar is shown but I get this error:
android.view.InflateException: Binary XML file line #12 in com.jaimegc.covid19tracker:layout/item_total: Binary XML file line #12 in com.jaimegc.covid19tracker:layout/item_total: Error inflating class com.google.android.material.card.MaterialCardView
Caused by: android.view.InflateException: Binary XML file line #12 in com.jaimegc.covid19tracker:layout/item_total: Error inflating class com.google.android.material.card.MaterialCardView
Caused by: java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
And using R.style.Theme_MaterialComponents
I have the same problem as in the first case. What would be the way to initialize the fragment with its actionbar? I could create a toolbar but I would like to avoid it if there are alternatives. Thanks!