在Android Studio上实现材料按钮错误

hwazgwia  于 2022-11-16  发布在  Android
关注(0)|答案(1)|浏览(169)

我在执行材料按钮时遇到问题,并得到如下错误。我尝试了不同的解决方案,但似乎不知道为什么它总是显示这个错误。任何帮助都将不胜感激。提前感谢

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.app.lifeadvicequotes, PID: 8603
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.lifeadvicequotes/com.app.lifeadvicequotes.MainActivity}: android.view.InflateException: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Error inflating class com.google.android.material.button.MaterialButton
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4111)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8751)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
     Caused by: android.view.InflateException: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Error inflating class com.google.android.material.button.MaterialButton
     Caused by: android.view.InflateException: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Error inflating class com.google.android.material.button.MaterialButton

这是我的样式xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/text_color_primary</item>
    </style>

        <!-- Base application theme. -->
        <style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>

    <style name="AppTheme.Button" parent="android:Widget.Material.Button">
        <item name="colorButtonNormal">#FFFFFF</item>
        <item name="android:textColor">#000000</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="NavigationDrawerStyle">
        <item name="android:textSize">16sp</item>
    </style>

</resources>
blmhpbnm

blmhpbnm1#

该问题可能来自parent=“android:Widget.Material.Button”尝试将其更改为parent=“Widget.MaterialComponents.Buttonparent=“Base.Widget.AppCompat.Button”(如果尚未导入材料组件库)

相关问题