You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to show Beagle view on activities which uses non-material theme, app crashes ( Drawer ) or dialog not shown ( Modal).
I think it is caused by using MaterialButton class in xml or code.
Is it possible to replace MaterialButton to Button?
crash log is like below:
java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:247)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:216)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:144)
at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:76)
at com.google.android.material.button.MaterialButton.<init>(MaterialButton.java:230)
I've assigned non-material theme in init function like below:
Hi!
Thanks for bringing this up.
Indeed the current version of the library expects a Material theme.
But you're right, there's no reason for using MaterialButton (if your Activity has a Material theme, the layout inflater will replace all Views with their Material counterparts - something I didn't know back then).
I'll make sure to fix this in the next update, hopefully in the coming days. I'll keep you posted!
@pandulapeter thanks for the reply.
If you expect material-theme in this library, what about to wrap context with material-themed context?
This is code snippet I am using in my project
fun Activity.toMaterialContext(): Context {
// this code is dangerous - using private material theme attributeval typedArray =this.theme.obtainStyledAttributes(intArrayOf(com.google.android.material.R.attr.isMaterialTheme))
val isMaterialTheme = typedArray.getBoolean(0, false)
typedArray.recycle()
returnif (isMaterialTheme) {
this
} else {
wrapMaterialTheme( R.style.my_default_material_theeme )
)
}
}
fun Activity.wrapMaterialTheme(@StyleRes newMaterialThemeResId:Int): Context {
returnContextThemeWrapper(
this,
newMaterialThemeResId
).apply {
val materialContext =thisval delegate =AppCompatDelegate.create(
materialContext,
requireNotNull(this),
null
)
val inflater =LayoutInflater.from(materialContext)
LayoutInflaterCompat.setFactory2(
inflater,
delegate asLayoutInflater.Factory2
)
}
}
If you apply this code, you can ensure library is using material themed context. But if user is applyed non-material theme, their theme is overridden. But I don't think this cause big(?) problem.
When trying to show Beagle view on activities which uses non-material theme, app crashes ( Drawer ) or dialog not shown ( Modal).
I think it is caused by using
MaterialButton
class in xml or code.Is it possible to replace
MaterialButton
toButton
?crash log is like below:
I've assigned non-material theme in
init
function like below:The text was updated successfully, but these errors were encountered: