[英]Adding Material Button in XML causing app to crash
When I add the following code to the layout.xml file, the app crashes, when the layout is loaded. 当我将以下代码添加到layout.xml文件时,加载布局时应用程序崩溃。
Code: 码:
<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" />
I checked my app gradle file and found 我检查了我的应用程序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'
So, the required design, support, appcompat dependencies are present. 因此,存在所需的设计,支持和appcompat依赖项。
Note: No other code apart from the above has been added, ie, the app works fine if I don't add the Material button in XML and crashes, if I add the Material Button in the XML. 注意:除上述代码外,未添加其他代码,即,如果我未在XML中添加“材质”按钮,则该应用程序运行正常,如果在XML中添加了“材质”按钮,则该应用程序崩溃。
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
for MaterialButton to work, your app theme must inherit from Theme.MaterialComponents (or a descendant) Hope it helps. 为了使MaterialButton正常工作,您的应用程序主题必须继承自Theme.MaterialComponents(或子孙),希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.