web-dev-qa-db-ja.com

エラー:IllegalArgumentException:このコンポーネントのスタイルでは、アプリのテーマがTheme.MaterialComponentsである必要があります

以下は私の依存関係です

implementation 'com.google.Android.material:material:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

私のlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    xmlns:app="http://schemas.Android.com/apk/res-auto"
    Android:id="@+id/main_content"
    Android:layout_width="match_parent"
    Android:layout_height="match_parent"
    Android:background="#ffffff"
    Android:fitsSystemWindows="true">


    <com.google.Android.material.bottomappbar.BottomAppBar
        Android:id="@+id/bottomBar"
        style="@style/Widget.MaterialComponents.BottomAppBar"
        Android:layout_width="match_parent"
        Android:layout_height="wrap_content"
        Android:layout_gravity="bottom"
        Android:backgroundTint="@color/colorPrimary"
        app:fabAlignmentMode="center"
        app:fabCradleMargin="10dp"
        app:fabCradleVerticalOffset="4dp"
        app:navigationIcon="@drawable/ic_drawer" >

    </com.google.Android.material.bottomappbar.BottomAppBar>

    <com.google.Android.material.floatingactionbutton.FloatingActionButton
        Android:id="@+id/fab"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        app:layout_anchor="@id/bottomBar"
        app:srcCompat="@drawable/ic_apps" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

上記のコードは私にとってはうまく機能しています

しかし、material designdependenciesを更新すると

implementation 'com.google.Android.material:material:1.1.0-alpha01'

エラーが発生しています。

Java.lang.RuntimeException: Unable to start activity ComponentInfo{neel.com.bottomappbar/neel.com.bottomappbar.MainActivity}: Android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.google.Android.material.bottomappbar.BottomAppBar
        at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2485)
        at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2545)
        at Android.app.ActivityThread.access$1100(ActivityThread.Java:151)
        at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1396)
        at Android.os.Handler.dispatchMessage(Handler.Java:102)
        at Android.os.Looper.loop(Looper.Java:157)
        at Android.app.ActivityThread.main(ActivityThread.Java:5602)
        at Java.lang.reflect.Method.invoke(Native Method)
        at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:774)
        at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:652)
     Caused by: Android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.google.Android.material.bottomappbar.BottomAppBar
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:543)
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:427)
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.Java:469)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.Java:140)
        at neel.com.bottomappbar.MainActivity.onCreate(MainActivity.kt:16)
        at Android.app.Activity.performCreate(Activity.Java:6358)
        at Android.app.Instrumentation.callActivityOnCreate(Instrumentation.Java:1108)
        at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2438)
        at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2545) 
        at Android.app.ActivityThread.access$1100(ActivityThread.Java:151) 
        at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1396) 
        at Android.os.Handler.dispatchMessage(Handler.Java:102) 
        at Android.os.Looper.loop(Looper.Java:157) 
        at Android.app.ActivityThread.main(ActivityThread.Java:5602) 
        at Java.lang.reflect.Method.invoke(Native Method) 
        at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:774) 
        at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:652) 
     Caused by: Android.view.InflateException: Binary XML file line #11: Error inflating class com.google.Android.material.bottomappbar.BottomAppBar
        at Android.view.LayoutInflater.createView(LayoutInflater.Java:649)
        at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:768)
        at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:708)
        at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:839)
        at Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:802)
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:519)
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:427) 
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:374) 
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.Java:469) 
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.Java:140) 
        at neel.com.bottomappbar.MainActivity.onCreate(MainActivity.kt:16) 
        at Android.app.Activity.performCreate(Activity.Java:6358) 
        at Android.app.Instrumentation.callActivityOnCreate(Instrumentation.Java:1108) 
        at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2438) 
        at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2545) 
        at Android.app.ActivityThread.access$1100(ActivityThread.Java:151) 
        at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1396) 
        at Android.os.Handler.dispatchMessage(Handler.Java:102) 
        at Android.os.Looper.loop(Looper.Java:157) 
        at Android.app.ActivityThread.main(ActivityThread.Java:5602) 
        at Java.lang.reflect.Method.invoke(Native Method) 
        at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:774) 
        at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:652) 
     Caused by: Java.lang.reflect.InvocationTargetException
        at Java.lang.reflect.Constructor.newInstance(Native Method)
        at Android.view.LayoutInflater.createView(LayoutInflater.Java:623)
        at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:768) 
        at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:708) 
        at Android.view.LayoutInflater.rInflate(LayoutInflater.Java:839) 
        at Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:802) 
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:519) 
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:427) 
        at Android.view.LayoutInflater.inflate(LayoutInflater.Java:374) 
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.Java:469) 
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.Java:140) 
        at neel.com.bottomappbar.MainActivity.onCreate(MainActivity.kt:16) 
        at Android.app.Activity.performCreate(Activity.Java:6358) 
        at Android.app.Instrumentation.callActivityOnCreate(Instrumentation.Java:1108) 
        at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2438) 
        at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2545) 
        at Android.app.ActivityThread.access$1100(ActivityThread.Java:151) 
        at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1396) 
        at Android.os.Handler.dispatchMessage(Handler.Java:102) 
        at Android.os.Looper.loop(Looper.Java:157) 
        at Android.app.ActivityThread.main(ActivityThread.Java:5602) 
        at Java.lang.reflect.Method.invoke(Native Method) 
        at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:774) 
        at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:652) 
     Caused by: Java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
        at com.google.Android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.Java:240)
        at com.google.Android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.Java:215)
        at com.google.Android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.Java:143)
        at com.google.Android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.Java:78)
        at com.google.Android.material.bottomappbar.BottomAppBar
16
Goku

material:1.1.0-alpha01に問題があります

シンプルな2つのソリューション

最初のソリューション

親テーマを変更する

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->

</style>

2番目のソリューション

安定版になるまでmaterial designの古いdependenciesを使用

implementation 'com.google.Android.material:material:1.0.0'

これが他の誰かに役立つことを願っています

11
Goku

Gradleの依存関係を変更し、コードをスタイルコードでうまく機能させる

<!-- Base application theme. -->
<style name="AppTheme" parent="**Theme.MaterialComponents.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="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="Android:activatedBackgroundIndicator">@drawable/drawer_list_selector</item>
    <item name="Android:textColorSecondary">@color/black_overlay</item>
    <!--<item name="Android:windowBackground">@drawable/nav_menu_background</item>-->
</style>

Gradleの依存関係

implementation 'com.google.Android.material:material:1.1.0-alpha06'
0
Sonu Kumar