티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

This Activity already has an action bar supplied by the window decor

이 액티비티에는 이미 윈도우 데코에서 제공한 액션바가 있습니다.

 문제 내용 

Trying to move over my stuff to use Toolbar instead of action bar but I keep getting an error saying

액션바 대신 툴바를 사용하기 위해 내 항목 위로 이동하려고 시도하지만 다음과 같은 오류가 계속 발생합니다.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tyczj.weddingalbum/com.xxx.xxx.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5039)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
            at android.support.v7.app.ActionBarActivityDelegateBase.setSupportActionBar(ActionBarActivityDelegateBase.java:165)
            at android.support.v7.app.ActionBarActivity.setSupportActionBar(ActionBarActivity.java:92)
            at com.xxx.xxx.MainActivity.onCreate(MainActivity.java:113)
            at android.app.Activity.performCreate(Activity.java:5104)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5039)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)

 

so then I added in my style for my activity to have no actionbar

그래서 저는 액티비티에 스타일에 액션바가 없도록 스타일을 추가했습니다.
<style name="AppCompatTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:windowActionBar">false</item>
</style>

 

and the theme is applies to activties in my manifest

그리고 그 테마는 제 매니페스트의 액티비티에 적용됩니다.
<activity
        android:name=".MainActivity"
        android:windowSoftInputMode="adjustResize|stateHidden"
        android:theme="@style/AppCompatTheme" android:screenOrientation="portrait"/>

 

MainActivity extends GooglePlayServiceActivity so I also set the theme there too

MainActivity는 GooglePlayServiceActivity를 상속받았고, 그래서 저는 또한 거기에 테마를 설정했습니다.
<activity
       android:name=".GooglePlayServicesActivity"
       android:label="@string/title_activity_google_play_services"
       android:theme="@style/AppCompatTheme">

 

but I still get the error. I also do not request window feature anywhere. any ideas why I still get this?

하지만 아직도 오류가 나요. 나는 또한 윈도우 기능을 어디에도 요청하지 않는다. 내가 왜 아직도 이걸 이해하는지 알아?

 

 

 

 높은 점수를 받은 Solution 

I think you're developing for Android Lollipop, but anyway include this line:

안드로이드 롤리팝을 위해 개발하고 있다고 생각하지만, 어쨌든 다음과 같은 라인을 포함하세요.
<item name="windowActionBar">false</item> 

 

to your theme declaration inside of your app/src/main/res/values/styles.xml.

app/src/main/res/values/styles.xml 내부의 테마 선언에

 

Also, if you're using AppCompatActivity support library of version 22.1 or greater, add this line:

또한 버전 22.1 이상의 AppCompatActivity 서포트 라이브러리를 사용하는 경우 다음 줄을 추가하세요.
<item name="windowNoTitle">true</item>

 

Your theme declaration may look like this after all these additions:

이러한 모든 추가 후 테마 선언은 다음과 같을 수 있습니다.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.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>
</style>

 

 

 가장 최근 달린 Solution 

Its very simple you just need to go with any one step out of two..

아주 간단합니다. 두 단계 중 하나만 수행하면 됩니다.

 

  1. change your device display mode from Dark mode to normal mode or .
  2. In style.xml if you are using AppCompat then add these 2 lines in your theme/style..<item name="windowActionBar">false</item> <item name="windowNoTitle">true</item>
1. 장치 디스플레이 모드를 다크 모드에서 일반 모드 또는 로 변경합니다.
2. AppCompat을 사용하는 경우 style.xml에서 테마/스타일에 다음 두 줄을 추가합니다..<item name="windowActionBar">false</item> <item name="windowNoTitle">true</item>

 

 

 

출처 : https://stackoverflow.com/questions/26515058/this-activity-already-has-an-action-bar-supplied-by-the-window-decor

반응형
댓글
공지사항
최근에 올라온 글