본문 바로가기

Android/오류해결

[Android] Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).


머티리얼 컴포넌트 테마도 extend 하려고했더니 없다면서 안되고, 이미 있는 테마 갖다쓰려니 똑같이 안되고

결국 공식 문서에 다 나와있었는데 영어 해석이 안돼서 삽질이 오래됐다;;;

공식문서 : https://material.io/develop/android/docs/getting-started/

그래들도 추가하고 하라는거 다했는데 중요한 4번을 빼먹어서 문제였다.

4. Change your app theme to inherit from a Material Components theme

Doing an app-wide migration by changing your app theme to inherit from a Material Components theme is the recommended approach. However, be sure to test thoroughly afterwards, as components in existing layouts may change their looks and behavior.

Note: If you can’t change your theme, you can do one of the following:

  • Inherit from one of our Material Components Bridge themes. See the Bridge Themes section for more details.
  • Continue to inherit from an AppCompat theme and add some new theme attributes to your theme. See the App Compat Themes section for more details.

그냥 하라는대로 했으면 됐는데...ㅠㅠ

styles.xml 로 가서 아래처럼 바꿔치기 하면 된다.

머티리얼 컴포넌트 재정의도 저렇게 하면 끝이다.