소프트웨어/Android

안드로이드(android): This Activity already has an action bar supplied by the window decor 에러

G. Hong 2021. 2. 9. 14:13
728x90
반응형

증상

안드로이드 어플리케이션 실행 시에 아래 에러메시지가 발생하고 어플리케이션이 실행되지 않음.

 

2021-02-09 10:30:05.237 18470-18470/com.example.testcode E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.testcode, PID: 18470
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testcode/com.example.testcode.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)

 

원인

Toolbar를 사용 할 때에는 action bar를 false하여야 하는데, 제대로 false가 되지 않은 상태로 인식이 되어서 발생하는 문제.

 

해결 방법

우선 res - themes - themes.xml (예전 styles.xml) 에서 아래와 같은 style을 지정합니다. name은 달라도 됩니다.

 

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

 

다음으로 manifest 파일에서 해당 activity에서 아래와 같이 추가를 해줍니다.

 

    <activity android:name=".YourActivity"  
     android:theme="@style/AppTheme.NoActionBar">

 

 

수정 예시

manifest 파일에 application의 theme도 지정이 되어야 합니다. 위의 예시는 직접 만든 style(TabExperiment)이고, 아래 예시는 안드로이드 스튜디오에서 기본적으로 선택이 가능한 style(AppCompat.Light)입니다.

 

<application
        android:theme="@style/Theme.AppCompat.Light"
</application>

 

728x90
반응형