ActionBarCompat : java.lang.IllegalStateException : Theme.AppCompat를 사용해야합니다.
나는 안드로이드 2.3.5에서의 RuntimeException을 얻고있다하지만 난 하고 Theme.AppCompat (고해상도 / 값 / themes.xml)를 사용하여. 이것은 전화입니다 : http://www.gsmarena.com/samsung_galaxy_y_s5360-4117.php
<!-- res/values/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Styled" parent="@style/Theme.AppCompat">
<item name="actionBarStyle">@style/QueryActionBar</item>
<item name="android:actionBarStyle">@style/QueryActionBar</item>
</style>
<style name="QueryActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="background">@color/blueback</item>
<item name="android:background">@color/blueback</item>
<item name="backgroundSplit">@color/blueback</item>
<item name="android:backgroundSplit">@color/blueback</item>
</style>
</resources>
다음은 values-v11에 대한 파일입니다.
<!-- res/values-v11/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="QueryTheme" parent="@android:style/Theme.Holo">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
</resources>
여기에 오류가 있습니다.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.txt2lrn.www/com.txt2lrn.www.LandingActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:102)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at com.txt2lrn.www.LandingActivity.onCreate(LandingActivity.java:95)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
죄송합니다. AndroidManifest.xml에 android : theme = "@ style / Theme.Styled"도 정의되어 있습니다.
MainActivity에서 ActionBarActivity를 확장하는 경우 values-v11에서도 상위 테마를 변경해야합니다.
따라서 values-v11의 style.xml은 다음과 같습니다.
<!-- res/values-v11/themes.xml -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="QueryTheme" parent="@style/Theme.AppCompat">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
</resources>
편집 : ActionBar 사용을 중지하고 Android 디자인 지원 라이브러리에 포함 된 AppBar 레이아웃 사용을 시작하는 것이 좋습니다.
ActionBar Compat를 추가하려면 활동 또는 애플리케이션이 다음과 같이 AndroidManifest.xml에서 @ style / Theme.AppCompat 테마를 사용해야합니다.
<activity
...
android:theme="@style/Theme.AppCompat" />
그러면 활동에 액션 바가 추가됩니다 (또는이 테마를 애플리케이션에 추가 한 경우 모든 활동).
그러나 일반적으로 작업 표시 줄을 사용자 정의해야합니다. 이렇게하려면 "@ style / Theme.AppCompat.Light"와 같이 Theme.AppCompat 부모를 사용하여 두 가지 스타일을 만들어야합니다. 첫 번째는 api 11> = (안드로이드 액션 바에 빌드 된 안드로이드 버전), 두 번째는 api 7-10 (액션 바에 빌드 없음)을위한 것입니다.
첫 번째 스타일을 살펴 보겠습니다. 그것은에 위치 할 고해상도 / 값-V11 / styles.xml . 다음과 같이 표시됩니다.
<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 11+ -->
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 11+ -->
<item name="android:background">@drawable/ab_custom_solid_styled</item>
<item name="android:backgroundStacked"
>@drawable/ab_custom_stacked_solid_styled</item>
<item name="android:backgroundSplit"
>@drawable/ab_custom_bottom_solid_styled</item>
</style>
And you need to have same style for api 7-10. It will be located in res/values/styles.xml, BUT because that api levels don't yet know about original android actionbar style items, we should use one, provided by support library. ActionBar Compat items are defined just like original android, but without "android:" part in the front:
<style name="Theme.Styled" parent="@style/Theme.AppCompat.Light">
<!-- Setting values in the default namespace affects API levels 7-11 -->
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the default namespace affects API levels 7-11 -->
<item name="background">@drawable/ab_custom_solid_styled</item>
<item name="backgroundStacked">@drawable/ab_custom_stacked_solid_styled</item>
<item name="backgroundSplit">@drawable/ab_custom_bottom_solid_styled</item>
</style>
Please mark that, even if api levels higher than 10 already have actionbar you should still use AppCompat styles. If you don't, you will have this error on launch of Acitvity on devices with android 3.0 and higher:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Here is link this original article http://android-developers.blogspot.com/2013/08/actionbarcompat-and-io-2013-app-source.html written by Chris Banes.
P.S. Sorry for my English
Check and make sure that you do not have another values folder that references theme.styled and does not use AppCompat theme
ie values-v11
folder
Try this...
styles.xml
<resources>
<style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
AndroidManifest.xml
<activity
android:name="com.example.Home"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Your Activity
is extending ActionBarActivity
which requires the AppCompat.theme
to be applied. Change from ActionBarActivity
to Activity
or FragmentActivity
, it will solve the problem.
Just do it Build -> Clean Project. I think this will solve your problem.
My manifest does not reference any themes... it should not have to AFAIK
Sure it does. Nothing is going to magically apply Theme.Styled
to an activity. You need to declare your activities -- or your whole application -- is using Theme.Styled
, e.g., :
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Styled">
I encountered this error when I was trying to create a DialogBox when some action is taken inside the CustomAdapter class. This was not an Activity but an Adapter class. After 36 hrs of efforts and looking up for solutions, I came up with this.
Send the Activity as a parameter while calling the CustomAdapter.
CustomAdapter ca = new CustomAdapter(MyActivity.this,getApplicationContext(),records);
Define the variables in the custom Adapter.
Activity parentActivity;
Context context;
Call the constructor like this.
public CustomAdapter(Activity parentActivity,Context context,List<Record> records){
this.parentActivity=parentActivity;
this.context=context;
this.records=records;
}
And finally when creating the dialog box inside the adapter class, do it like this.
AlertDialog ad = new AlertDialog.Builder(parentActivity).setTitle("Your title");
and so on..
I hope this helps you
I just get my application move from ActionBarSherlock to ActionBarCompat. Try declare your old theme like this:
<style name="Theme.Event" parent="Theme.AppCompat">
Then set the theme in your AndroidManifest.xml:
<application
android:debuggable="true"
android:name=".activity.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Event.Home"
>
I had such crash on Samsung devices even though the activity did use Theme.AppCompat. The root cause was related to weird optimizations on Samsung side:
- if one activity of your app has theme not inherited from Theme.AppCompat
- and it has also `android:launchMode="singleTask"`
- then all the activities that are launched from it will share the same Theme
My solution was just removing android:launchMode="singleTask"
in my case i made a custom view i added to custom view constructor
new RoomView(getAplicationContext());
the correct context is activity so changed it to:
new RoomView(getActivity());
or
new RoomView(this);
For my list view am using custom Adapter which extends ArrayAdapter. in listiview i have 2 buttons one of the buttons as Custom AlertDialogBox. Ex: Activity parentActivity; Constructor for Adapter `
public CustomAdapter(ArrayList<Contact> data, Activity parentActivity,Context context) {
super(context,R.layout.listdummy,data);
this.mContext = context;
this.parentActivity = parentActivity;
}
` calling Adapter from MainActivty
adapter = new CustomAdapter(dataModels,MainActivity.this,this);
now write ur alertdialog inside ur button which is in the Adapter class
viewHolder.update.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(parentActivity);
alertDialog.setTitle("Updating");
alertDialog.setCancelable(false);
LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@SuppressLint("InflateParams") final View view1 = layoutInflater.inflate(R.layout.dialog,null);
alertDialog.setView(view1);
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
alertDialog.setPositiveButton("Update", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//ur logic
}
}
});
alertDialog.create().show();
}
});
para resolver o meu problema, eu apenas adicionei na minha MainActivity ("Theme = To solve my problem, I just added it in my MainActivity ("Theme =" @ style / MyTheme "") where MyTheme is the name of my theme
[Activity(Label = "Name Label", MainLauncher = true, Icon = "@drawable/icon", LaunchMode = LaunchMode.SingleTop, Theme = "@style/MyTheme")]
'IT박스' 카테고리의 다른 글
UIImageView에서 색조 색상 사용 (0) | 2020.08.17 |
---|---|
몽구스는 왜 항상 내 컬렉션 이름 끝에 s를 추가합니까? (0) | 2020.08.16 |
사용하는 방법 (0) | 2020.08.16 |
getJSON을 사용하여 post 메소드로 데이터를 보내는 방법은 무엇입니까? (0) | 2020.08.16 |
Git 저장소에서 파일을 제거하지 못했습니다. 새 백업을 만들 수 없습니다. (0) | 2020.08.16 |