java - 为什么在使用 Material 按钮时我的应用程序会崩溃?
问题描述
我想使用 materail 按钮,但是当我编写并运行程序时,程序崩溃了。我需要什么帮助?
这是我的代码
<com.google.android.material.button.MaterialButton
style="@style/TextAppearance.MaterialComponents.Button"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
这个 build.gradle
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'com.wang.avi:library:2.1.3'
implementation 'com.github.pwittchen:swipe-rx2:0.3.0'
implementation 'com.ogaclejapan.smarttablayout:library:2.0.0@aar'
implementation 'com.ogaclejapan.smarttablayout:utils-v4:2.0.0@aar'
implementation 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.github.bumptech.glide:glide:3.8.0'
implementation 'org.greenrobot:eventbus:3.1.1'
解决方案
要使 MaterialButton 工作,App 主题必须从 Theme.MaterialComponents (或后代)继承
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
推荐阅读
- python - 无法导入 Python 模块,因为“sys.path”和“sys.executable”存在差异
- python - 如何正确结束 Python 中的 if else 语句(寻宝游戏问题)?
- java - 使用 CMU Sphinx 的 Java 实时语音识别器中的 IllegalArgumentException
- javascript - 如何使用 html css 制作工具提示框阴影
- javascript - 计算 JSON API 结果的最大值和平均值
- javascript - 在 Typescript 模块中导入 npm/buffer 包
- android - 世博人脸检测角度
- java - 如何在Java中正确初始化静态数组字段
- sql - 简单查询的问题
- javascript - jQuery:删除特定的li /附加按钮到附加的li