在XML中添加材料按钮导致应用程序崩溃



当我将以下代码添加到layout.xml文件时,当加载布局时,应用程序崩溃。

代码:

<android.support.design.button.MaterialButton
android:id="@+id/b_p_add"
android:layout_width="143dp"
android:layout_height="38dp"
android:layout_below="@+id/et_p_addl_notes"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp" />

我检查了我的应用程序gradle文件,发现

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'

因此,提供了所需的设计、支持和appcompat依赖关系。

注意:除了上面的代码之外,没有添加其他代码,也就是说,如果我不在XML中添加Material按钮,应用程序就会正常工作,如果我在XML中增加Material按钮就会崩溃。

请将您的应用程序主题更改为:<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<style name="AppTheme" parent="Theme.MaterialComponents.Light">

若要使MaterialButton工作,您的应用程序主题必须继承自theme。材料组件(或子体(希望能有所帮助。