gpt4 book ai didi

android - 在 XML 中添加 Material 按钮导致应用程序崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 07:42:30 26 4
gpt4 key购买 nike

当我将以下代码添加到 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.MaterialComponents(或后代)希望对您有所帮助。

关于android - 在 XML 中添加 Material 按钮导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53023859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com