Fixed
Status Update
Comments
il...@google.com <il...@google.com>
hu...@google.com <hu...@google.com> #2
Thank you for the bug report, Russell.
Using Theme.AppCompat in EmptyFragmentActivity sounds good to me. Let me work on the fix.
Using Theme.AppCompat in EmptyFragmentActivity sounds good to me. Let me work on the fix.
ru...@gmail.com <ru...@gmail.com> #3
Thanks for the follow up, it appears I have misspoken and the error is with using views from Material Components library (Theme.MaterialCompnents rather than Theme.Material). I've just tried using Theme.AppCompat myself and this also breaks.
I'm not actually sure if there can be a library fix here since the libraries aren't tightly coupled and the material components library force specific theme attrs to be available (and thus referencing these attrs causes the crash). The workaround I posted may be sufficient, I just wanted to bring this up to the team so in the worst case a note can be added to documentation.
I'm not actually sure if there can be a library fix here since the libraries aren't tightly coupled and the material components library force specific theme attrs to be available (and thus referencing these attrs causes the crash). The workaround I posted may be sufficient, I just wanted to bring this up to the team so in the worst case a note can be added to documentation.
hu...@google.com <hu...@google.com> #4
Hmm, that's too bad. Agreed, introducing a dependency to the material component doesn't sound a right option. FragmentScenario probably needs an another launch method taking activity's theme and call setTheme before views are instantiated. Let me try building a prototype.
om...@gmail.com <om...@gmail.com> #7
Sorry for interrupt, but I found this bug occur in fragment-testing 1.1.0-alpha09 again.
Here is my small project to reproduce it. (Reproduced in both AS 3.6.1 Canary 1 and AS 3.4.1)
Just run the `androidTest/LoginFragmentInstrumentedTest` as these two images show.
Here is my small project to reproduce it. (Reproduced in both AS 3.6.1 Canary 1 and AS 3.4.1)
Just run the `androidTest/LoginFragmentInstrumentedTest` as these two images show.
il...@google.com <il...@google.com> #8
Re #7 - you have to use one of the overloads to launchFragmentInContainer that take the theme resource ID for it to use a custom theme:
private val loginFragmentScenario = launchFragmentInContainer<LoginFragment>(
themeResId = R.style.Theme_Shrine)
private val loginFragmentScenario = launchFragmentInContainer<LoginFragment>(
themeResId = R.style.Theme_Shrine)
om...@gmail.com <om...@gmail.com> #9
Re #8
Yes, this way will "fix" this issue. But you could find that the "Theme_Shrine" is actually a descendant of "Theme.MaterialComponents.Light.NoActionBar" which is a "Theme.Appcompat.Light".
Therefore, I wonder if the solution you post above is by designed or a bug.
Yes, this way will "fix" this issue. But you could find that the "Theme_Shrine" is actually a descendant of "Theme.MaterialComponents.Light.NoActionBar" which is a "Theme.Appcompat.Light".
Therefore, I wonder if the solution you post above is by designed or a bug.
il...@google.com <il...@google.com> #10
You need to tell FragmentScenario what theme you want if you want something other than the default Theme.WithActionBar, that's correct.
Description
com.google.android.material:material:1.0.0
Using FragmentScenario to launch a Fragment with a MaterialButton, my instrumentation test crashes with:
"IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant)."
It appears that the EmptyFragmentActivity in FragmentScenario doesn't inherent a compatible theme with Material. I am currently working around this issue by manually overriding the EmptyFragmentActivity theme with a material one:
<style name="FragmentScenarioEmptyFragmentActivityTheme" parent="@style/Theme.MaterialComponents">
<item name="android:windowIsFloating">false</item>
</style>