관리 메뉴

나만을 위한 블로그

[Android] You need to use a Theme.AppCompat theme (or descendant) with this activity 에러 해결 본문

Android

[Android] You need to use a Theme.AppCompat theme (or descendant) with this activity 에러 해결

참깨빵위에참깨빵 2020. 10. 1. 20:58
728x90
반응형

액티비티를 풀스크린 모드로 사용하는 기능을 구현할 일이 있어서 코딩하던 도중 저런 에러를 발견했다.

theme 단어 보니깐 테마 쪽에서 실수했나 싶어 찾아봤지만 빨간 줄이 생겨 있거나 이상한 점은 찾지 못했다.

그럼 이 에러는 대체 왜 생기는 걸까?

 

원인은 AppCompatActivity를 상속받은 액티비티에서 NoTitleBar 옵션을 사용하기 때문이다.

res/styles.xml 파일의 내용을 보면, 처음 프로젝트를 만들 때 이런 내용의 코드가 만들어져 있는 걸 볼 수 있다.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

여기서 parent를 보면 Theme.Appcompat 어쩌고 하는 문장이 보인다.

바로 이 문장이 원인의 핵심이다. 내가 사용한 style의 parent 부분은 저런 Theme로 시작하는 문장이 아니었다.

 

그럼 어떻게 해야 할까?

public class 액티비티명 extends AppCompatActivity 라고 써져 있는 부분에서 AppCompatActivity를 Activity로 바꿨다.

작업중인 액티비티의 테마에선 AppCompat 속성이 있는 style을 쓰지 않을 거니까, 그냥 Activity로 바꿔버리면 되지 않을까? 해서 해본 것이었다.

이렇게 하니 정상적으로 잘 작동하는 걸 볼 수 있었다.

 

결론 : AppCompatActivity를 Activity로 바꾸니 해결됨

반응형
Comments