티스토리 뷰
'You need to use a Theme.AppCompat theme (or descendant) with this activity' 오류 수정하기
맨날치킨 2022. 12. 7. 11:05Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
You need to use a Theme.AppCompat theme (or descendant) with this activity
이 액티비티에는 Theme.AppCompat 테마(또는 이를 상속받은 테마)를 사용해야 합니다.
문제 내용
Android Studio 0.4.5
Android Studio 0.4.5
Android documentation for creating custom dialog boxes: http://developer.android.com/guide/topics/ui/dialogs.html
커스텀 대화상자를 만드는 Android 문서:
If you want a custom dialog, you can instead display an Activity as a dialog instead of using the Dialog APIs. Simply create an activity and set its theme to Theme.Holo.Dialog in the <activity>
manifest element:
만약 사용자 지정 대화상자를 원한다면, Dialog API를 사용하는 대신에 Activity를 대화상자로 표시할 수 있습니다. 단순히 Activity를 생성하고, AndroidManifest.xml의 요소에서 테마를 Theme.Holo.Dialog로 설정하면 됩니다.
<activity android:theme="@android:style/Theme.Holo.Dialog" >
However, when I tried this I get the following exception:
하지만 이를 시도해본 결과 다음 예외가 발생합니다:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
I am supporting the following, and I can't using something greater than 10 for the min:
제가 지원하는 것은 다음과 같습니다. 최소 버전으로 10보다 큰 버전은 사용할 수 없습니다.
minSdkVersion 10
targetSdkVersion 19
In my styles I have the following:
제 스타일에는 다음과 같은 항목이 있습니다:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
And in my manifest I have this for the activity:
그리고 매니페스트에서 이렇게 액티비티를 설정합니다:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:theme="@android:style/Theme.Holo.Light.Dialog"
android:name="com.ssd.register.Dialog_update"
android:label="@string/title_activity_dialog_update" >
</activity>
Creating the dialog box like this was something I was hopping to do, as I have already completed the layout.
이렇게 대화 상자를 만드는 것은 이미 레이아웃을 완료했기 때문에 원하던 것이었습니다.
Can anyone tell me how I can get around this problem?
이 문제를 어떻게 해결할 수 있는지 알려주실 수 있나요?
높은 점수를 받은 Solution
The reason you are having this problem is because the activity you are trying to apply the dialog theme to is extending ActionBarActivity
which requires the AppCompat
theme to be applied.
이 문제가 발생하는 이유는 당신이 다이얼로그 테마를 적용하려는 액티비티가 ActionBarActivity를 상속하고 있기 때문입니다. ActionBarActivity를 상속한 액티비티는 AppCompat 테마가 적용되어야 합니다.
Update: Extending AppCompatActivity
would also have this problem
업데이트: AppCompatActivity를 상속하더라도 이 문제가 발생할 수 있습니다.
In this case, change the Java inheritance from ActionBarActivity
to Activity
and leave the dialog theme in the manifest as it is, a non Theme.AppCompat
value
이 경우에는 ActionBarActivity에서 Activity로 Java 상속을 변경하고 매니페스트에 있는 다이얼로그 테마를 변경하지 않고 그대로 둡니다. 즉, Theme.AppCompat 값을 사용하지 않습니다.
The general rule is that if you want your code to support older versions of Android, it should have the AppCompat
theme and the java code should extend AppCompatActivity
. If you have *an activity that doesn't need this support, such as you only care about the latest versions and features of Android, you can apply any theme to it but the java code must extend plain old Activity
.
일반적인 규칙은 안드로이드의 이전 버전을 지원하려면 AppCompat 테마를 사용하고 자바 코드는 AppCompatActivity를 확장해야 한다는 것입니다. 그러나 최신 버전과 기능에만 관심이 있는 활동과 같이 *이러한 지원이 필요하지 않은 활동의 경우, 어떤 테마를 적용하더라도 자바 코드는 평범한 Activity를 확장해야 합니다.
NOTE: When change from AppCompatActivity
(or a subclass, ActionBarActivity
), to Activity
, must also change the various calls with "support" to the corresponding call without "support". So, instead of getSupportFragmentManager
, call getFragmentManager
.
참고: AppCompatActivity(또는 하위 클래스인 ActionBarActivity)에서 Activity로 변경할 때 "support"가 포함된 여러 호출을 "support" 없는 해당 호출로 변경해야합니다. 즉, getSupportFragmentManager 대신 getFragmentManager를 호출합니다.
가장 최근 달린 Solution
I came across this issue when using SplashScreen Api
, this error is also thrown when installSplashScreen()
is not called in the MainActivity
저는 MainActivity에서 installSplashScreen()을 호출하지 않았을 때 SplashScreen API를 사용할 때이 오류를 마주쳤습니다.
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
출처 : https://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity
'개발 > 안드로이드' 카테고리의 다른 글
웹뷰에 html이 정상적으로 로드되지 않을 때 시도해 볼만한 것 (0) | 2022.12.08 |
---|---|
텍스트뷰 링크를 클릭할 수 있도록 하는 방법 (0) | 2022.12.07 |
Android WebView 투명 배경 적용하기 (0) | 2022.12.07 |
Android ADB로 인텐트 보내기 (0) | 2022.12.07 |
Android 1.6: "Android.view.WindowManager$BadTokenException 수정하기 (0) | 2022.12.06 |