Recently, we moved to use the material design theme for our app (we are using version 1.4.0). As part of this, we are converting explicit <com.google.android.material.button.MaterialButton
declarations to <Button
since Button will be converted to MaterialButton behind the scene. Everything else works fine except in the following case.
We have a <com.google.android.material.button.MaterialButton
in a FrameLayout
as shown below
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent">
<Button
...
...
/>
</FrameLayout>
and it's being used as a custom view via view binding something like below
class MyView: FrameLayout {
private val binding by ViewGroupBindingProperty(MyViewBinding::inflate)
constructor(...)
/// other code
}
When I tried to convert above <com.google.android.material.button.MaterialButton to <Button, style is not applied (we have border color, strokeColor, etc applied as style for this button in xml) so I tried to cast this button as MaterialButton in MyView and tried to apply those style properties but it's throwing following error
Caused by: java.lang.ClassCastException: android.widget.Button cannot be cast to com.google.android.material.button.MaterialButton
at jp.ne.paypay.android.app.view.paymentMethod.MyView.init(MyView.kt:51)
at xx.xx.xx.xx.MyView.<init>(MyView.kt:29)
Any guidance on what could be wrong is highly appreciated. Thank you in advance.