Description: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
Expected behavior: shouldn't crash
Source code: MaterialAlertDialogBuilder(activity)
.setTitle(R.string.logout_title)
.setMessage(R.string.logout_message)
.setPositiveButton(R.string.logout_positive_btn_label, null)
.setNegativeButton(R.string.logout_negative_btn_label, null)
.create()
Theme:
Android API version: 29
Material Library version: com.google.android.material:material:1.2.0-alpha06
Device: Nokia 6.1 plus
To help us triage faster, please check to make sure you are using the latest version of the library.
We also happily accept pull requests.
Hi @shaikfaizal, can you make sure your base app theme inherits from a Theme.MaterialComponents theme?
@dsn5ft I'm having the same issue and my app theme inherits from Theme.MaterialComponents
@dsn5ft yah, which is inherited from the base app theme, but one thing, I can use an alert builder without any issues.
Can you attach a minimal sample app that reproduces the issue?
Top level theme
<style name="Base.Theme.MaterialThemeBuilder" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:statusBarColor" tools:ignore="NewApi">?attr/colorSurface</item>
<item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item>
<item name="android:navigationBarColor" tools:ignore="NewApi">
?android:attr/colorBackground
</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">true</item>
<item name="android:navigationBarDividerColor" tools:ignore="NewApi">
?attr/colorControlHighlight
</item>
</style>
Manifest
"application
android:name=".BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp"
android:usesCleartextTraffic="true""
HomeActivity
"activity
android:name=".HomeActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.MyApp.FullScreen.Launcher""
Dialog theme
```
**Theme added on base theme**
```
@dsn5ft any update on this?
Hi @shaikfaizal, thanks for providing the code snippets. However, it would be best if you could create a GitHub repo with a minimal app that reproduces the issue. In order for us to help it's important for us to see how everything is hooked up.
@shaikfaizal why are you explicitly settings all of these? It will default to those values but if ?attr/colorPrimary isn't defined I'm pretty sure it won't work.
<style name="ThemeOverlay.App.MaterialAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="colorPrimary">?attr/colorPrimary</item>
<item name="colorSecondary">?attr/colorSecondary</item>
<item name="colorSurface">?attr/colorSurface</item>
<item name="colorOnSurface">?attr/colorOnSurface</item>
<style name="Theme.MyApp" parent="Base.Theme.MyApp" />
@shaikfaizal Can you post your full theme? What is Base.Theme.MyApp ?