I know that this question has been asked before, but the provided answers did not solve my case, so I'll ask for an individual solution.
My code
My AndroidManifest.xml looks like this:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".KategorieAuswahl"
android:label="#string/title_activity_kategorie_auswahl" >
</activity>
<activity
android:name=".ZeigeFragen"
android:label="#string/title_activity_zeige_fragen" >
</activity>
</application>
And my styles.xml looks like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
I want my App to open in fullscreen and to hide the TitleBar. The first thing I did was to add a android:theme="#android:style/Theme.NoTitleBar.Fullscreen" attribute to the <application>-Tag of my AndroidManifest.xml.
This leads to the error You need to use a Theme.AppCompat theme (or descendant) with this activity. Here is the full stacktrace:
05-27 21:24:26.889 2121-2121/de.test.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.test.myapp/de.test.myapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
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.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at de.test.myapp.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
There are multiple questions on stackoverflow referencing this error.
Approach #1
One solution suggests to change the Java inheritance from ActionBarActivity to Activity and leave the manifest as it is.
So I updated my the <style> element in my styles.xml and removed the DarkActionBar part:
<style name="AppTheme" parent="Theme.AppCompat.Light">
This still gives me the same error.
Approach #2
The next solution suggests to change my styles.xml's parent attribute from
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to <style name="AppTheme" parent="Theme.AppCompat">
This makes it possible to use android:theme="#style/Theme.AppCompat.NoActionBar" for my <activity>, but I don't see an option to make it fullscreen then.
Approach #3
Another solution soggests to add <item name="android:windowNoTitle">true</item> to my <style> element but this doesn't change anything at all.
Conclusion
I really tried a lot, but nothing seems to work. Anyway I have problems understanding the theme inheritance chain and when I may use .NoTitleBar and .Fullscreen.
After all I don't care which theme to use, as long I can make the app fullscreen without a title bar. Can you help me to pick the right attributes?
extend ActionBarActivity or the new one, and use Theme.AppCompat.NoActionBar, now in your Activity
if (Build.VERSION.SDK_INT < 16) {
Activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}else{
Activity.getWindow().getDecorView().
setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}
Hope it helps..
Related
This question already has answers here:
You need to use a Theme.AppCompat theme (or descendant) with this activity
(63 answers)
Closed 4 years ago.
I am running across the following error while launching my app:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shantanu.fireaudit, PID: 24098
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:83)
at android.support.v7.app.AlertController.installContent(AlertController.java:231)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:278)
at android.app.Dialog.dispatchOnCreate(Dialog.java:389)
at android.app.Dialog.show(Dialog.java:293)
at com.example.shantanu.fireaudit.MainGroupActivity$1.onClick(MainGroupActivity.java:79)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Here is my AndroidManifest.xml where all activities with corresponding themes are defined.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GuidelinesActivity" />
<activity android:name=".FormActivity" />
<activity android:name=".MainGroupActivity"/>
<activity android:name=".LocationsActivity"/>
<activity
android:name=".Main2Activity"
android:label="#string/title_activity_main2"
android:theme="#style/AppTheme"></activity>
</application>
I think it has something to do with the Theme but can't figure it out.
In your res/values/style.xml the style AppTheme should be a Theme.AppCompat theme. For example:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Also make sure you are importing the android appcompat library in your app/build.gradle file.
dependencies {
implementation "com.android.support:appcompat-v7:27.1.1"
}
I looked at other SO posts and configured accordingly. But I still see this issue on some Android devices (4.3.1). It works 75% of time.
You need to use a Theme.AppCompat theme (or descendant) with this activity.
What is wrong with code below?
BaseActivity extends android.support.v7.appAppCompatActivity
<application
android:allowBackup="true"
android:theme="#style/AppTheme" >
All activities (crashed acitivity as well) use AppTheme from application tag. One activity uses:
<activity
android:name=".Activities.EntryActivity"
android:noHistory="true"
android:theme="#style/SplashTheme" >
I don't have any other style.xml.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
From Android:
<style name="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
java.lang.RuntimeException: Unable to start activity
ComponentInfo{Activities.MyAcitivity}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat
theme (or descendant) with this activity. 1 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
2 at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
3 at android.app.ActivityThread.access$600(ActivityThread.java:141)
4 at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
5 at android.os.Handler.dispatchMessage(Handler.java:99) 6 at
android.os.Looper.loop(Looper.java:137) 7 at
android.app.ActivityThread.main(ActivityThread.java:5103) 8 at
java.lang.reflect.Method.invokeNative(Native Method) 9 at
java.lang.reflect.Method.invoke(Method.java:525) 10 at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12 at com.android.internal.os.ZygoteInit.main(Native Method) 13 at
dalvik.system.NativeStart.main(Native Method) 14 Caused by:
java.lang.IllegalStateException: You need to use a Theme.AppCompat
theme (or descendant) with this activity. 15 at
android.support.v7.app.AppCompatDelegateImplV7.i(SourceFile:340) 16 at
android.support.v7.app.AppCompatDelegateImplV7.h(SourceFile:309) 17 at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:273)
18 at
android.support.v7.app.AppCompatActivity.setContentView(SourceFile:136)
19 at .Commons.BaseActivity.onCreate(SourceFile:236) 20 at
.MyActivity.onCreate(SourceFile:24) 21 at
android.app.Activity.performCreate(Activity.java:5133) 22 at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
23 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
24 ... 12 more 25 java.lang.IllegalStateException: You need to use a
Theme.AppCompat theme (or descendant) with this activity. 26 at
android.support.v7.app.AppCompatDelegateImplV7.i(SourceFile:340) 27 at
android.support.v7.app.AppCompatDelegateImplV7.h(SourceFile:309) 28 at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:273)
29 at
android.support.v7.app.AppCompatActivity.setContentView(SourceFile:136)
30 at Activities.Commons.BaseActivity.onCreate(SourceFile:236) 31 at
Activities.Accounts.AppLaunchActivity.onCreate(SourceFile:24) 32 at
android.app.Activity.performCreate(Activity.java:5133) 33 at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
34 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
35 at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
36 at android.app.ActivityThread.access$600(ActivityThread.java:141)
37 at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
38 at android.os.Handler.dispatchMessage(Handler.java:99) 39 at
android.os.Looper.loop(Looper.java:137) 40 at
android.app.ActivityThread.main(ActivityThread.java:5103) 41 at
java.lang.reflect.Method.invokeNative(Native Method) 42 at
java.lang.reflect.Method.invoke(Method.java:525) 43 at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
44 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
45 at com.android.internal.os.ZygoteInit.main(Native Method) 46 at
dalvik.system.NativeStart.main(Native Method)
try this:
in res/values/styles.xml:
<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>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Now in your manifest:
<application
android:theme="#style/AppTheme"> //base Application theme
<activity
android:name=".Activities.EntryActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"> //Activity Theme
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I am creating one application and i am getting error,
On launching it crash and says
Caused by: java.lang.IllegalStateException: You need to use a
Theme.AppCompat theme (or descendant) with this activity.
Here is my Activity:
public class SplashScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
finish();
}
}, 3000);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_splash_screen, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#style/MyAnimation.Window</item>
<item name="android:windowBackground">#color/background</item>
</style>
<!-- Application theme. -->
<style name="AppTheme1" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
Here is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme1" >
<activity
android:name=".activity.SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Here is complete error log:
FATAL EXCEPTION: main 10-16 15:56:26.135
25342-25342/com.social_infotech.renthouse E/AndroidRuntime:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.social_infotech.renthouse/com.social_infotech.renthouse.activity.SplashScreen}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat
theme (or descendant) with this activity. 10-16 15:56:26.135
25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
android.app.ActivityThread.access$600(ActivityThread.java:141) 10-16
15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
android.os.Handler.dispatchMessage(Handler.java:99) 10-16 15:56:26.135
25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at
android.os.Looper.loop(Looper.java:137) 10-16 15:56:26.135
25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at
android.app.ActivityThread.main(ActivityThread.java:5103) 10-16
15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native
Method) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
java.lang.reflect.Method.invoke(Method.java:525) 10-16 15:56:26.135
25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-16
15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: Caused by: java.lang.IllegalStateException: You
need to use a Theme.AppCompat theme (or descendant) with this
activity. 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:112)
10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148)
10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse
E/AndroidRuntime: at
com.social_infotech.renthouse.activity.SplashScreen.onCreate(SplashScreen.java:16)
Extends your activity with FragmentActivity or Activity
Because you are using NoAcionBar as your theme.
As I've said, something's not adding up.
You seem to be using different themes:
In the manifest you have
#style/AppTheme1
while the styles file contains
#style/AppTheme
Just copy your following code to your values-21 >>> Styles.xml
then clean your project and try to run.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#style/MyAnimation.Window</item>
<item name="android:windowBackground">#color/background</item>
</style>
<!-- Application theme. -->
<style name="AppTheme1" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
for a noActionBar activity :
style.xml
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
</style>
AndroidManifest.xml
<activity
android:name=".SplashScreenActivity"
android:theme="#style/AppThemeNoActionBar" >
</activity>
SplashScreen.java
import android.support.v7.app.AppCompatActivity;
public class SplashscreenActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
}
}
Please refer to this thread.
EDIT: A few answer from the above thread may help you with this issue. I'll list a summary:
molokoka's answer, in order to add ActionBarCompat in your activity or application should use #style/Theme.AppCompat theme in AndroidManifest.xml like this:
<activity
...
android:theme="#style/Theme.AppCompat" />
molokoka also states that usually you need to customize your ActionBar. Once again, please follow his answer for details.
tyczj also makes a very good point:
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.
Side note: Sorry, I'm unable to add a comment due to low reputation. That's the reason why I placed an answer.
Hello I' making this project in Android when i start the dialog Activity from Main Activity.
These are the related files:
Main Activity:http://pastebin.com/xyDbBSj4
Dialogs Activity:http://pastebin.com/f6jGC1CH
I have this error on logcat:
FATAL EXCEPTION: main
Process: com.android4dev.navigationview, PID: 30736
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android4dev.navigationview/com.android4dev.navigationview.ui.activities.DialogsActivity}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:122)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.android4dev.navigationview.ui.activities.BaseActivity.onCreate(BaseActivity.java:36)
at com.android4dev.navigationview.ui.activities.DialogsActivity.onCreate(DialogsActivity.java:43)
1- You should declare that your application will be stylized using Theme.AppCompat in your Android Manifest.
Something like this:
<activity
android:name=".my.packageactivity.MyOwnActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat"/>
2- Or maybe declare that the whole application will be stylized using AppCompat.
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat">
3- If you want to set your own style later, you'll have to create a style.xml.
3.1- Using the whole application:
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyOwnStyle">
3.2- Using the activity>
<activity
android:name=".my.packageactivity.MyOwnActivity"
android:label="#string/app_name"
android:theme="#style/MyOwnStyle"/>
And then set the parent to Theme.AppCompat inside your new style.xml file:
<resources>
<style name="MyOwnStyle" parent="Theme.AppCompat">
[...]
</style>
</resources>
I have put an update on google play and see this error :
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.jim2/com.jim2.SettingWidgetActivity}: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.access$500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:1007)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:919)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:251)
at com.jim2.SettingWidgetActivity.onCreate(SettingWidgetActivity.java:37)
at android.app.Activity.performCreate(Activity.java:4397)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
... 11 more
I don't understand why this error appear cause it's work perfectly on my devices
Anyone have an idea ?
Here is a part of my Manifest.xml
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
Thanks
Don't use android:theme="#style/Theme.Sherlock".
Use setTheme(R.style.Theme_Sherlock); inside OnCreate.
E.g.
#Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock);
super.onCreate(savedInstanceState);
// What you want to do here
}
You can just make your style inherit from Theme.Sherlock
<style name="MyAppTheme" parent="Theme.Sherlock">
then in manifest use your theme
android:theme="#style/MyAppTheme"
You do not have to use setTheme on every page as Muz said this seem like a lot of work when there are much better solutions, would mark the above answer down but I can't !!
I agree with matt_lethargic. In my style file was:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
My application stoped crashing after I changed it to:
<style name="AppBaseTheme" parent="Theme.Sherlock">