Error : IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

Below is my dependency

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

My 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> 

The Above code is working fine for me

But when i update the dependencies of material design

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

I'm getting below error

回答1:

There is some issue with material:1.1.0-alpha01

Simple two Solution

1st Solution

Change the parent theme

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

2nd solution

Use old dependencies of material design until stable version

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

Hope this helps to some one else



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!