我有一个小应用程序,我有一个标题栏。我想摆脱它,并读到我应该将清单中的主题更改为@android:style/Theme.NoTitleBar.Fullscreen
。 (那是@style/AppTheme
我必须从系统资源中浏览noTitle主题并添加它。
现在,如果我启动该应用程序,它会说它不幸地停止了工作#。
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.esrmdesign"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.esrmdesign.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>
</application>
</manifest>
activity_main.xml中:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.esrmdesign.MainActivity"
tools:ignore="MergeRootFrame" />
logcat的:
05-15 05:15:03.670: E/AndroidRuntime(908): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.esrmdesign/com.example.esrmdesign.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
05-15 05:15:03.670: E/AndroidRuntime(908): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.os.Handler.dispatchMessage(Handler.java:102)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.os.Looper.loop(Looper.java:136)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-15 05:15:03.670: E/AndroidRuntime(908): at java.lang.reflect.Method.invokeNative(Native Method)
05-15 05:15:03.670: E/AndroidRuntime(908): at java.lang.reflect.Method.invoke(Method.java:515)
05-15 05:15:03.670: E/AndroidRuntime(908): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-15 05:15:03.670: E/AndroidRuntime(908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-15 05:15:03.670: E/AndroidRuntime(908): at dalvik.system.NativeStart.main(Native Method)
05-15 05:15:03.670: E/AndroidRuntime(908): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
05-15 05:15:03.670: E/AndroidRuntime(908): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
05-15 05:15:03.670: E/AndroidRuntime(908): at com.example.esrmdesign.MainActivity.onCreate(MainActivity.java:18)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.app.Activity.performCreate(Activity.java:5231)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-15 05:15:03.670: E/AndroidRuntime(908): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-15 05:15:03.670: E/AndroidRuntime(908): ... 11 more
答案 0 :(得分:1)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
当您使用appcompat
库ActionBar
而未在清单文件中设置兼容主题时,会抛出此异常。兼容的主题可以是例如
android:theme="@style/Theme.AppCompat.Light"
如果您使用appcompat
库来支持API 7或更高版本的ActionBar
,则需要跟踪以下信息,
1.始终使用最新的appcompat
库。
2.不要忘记根据需要添加如下所示的兼容主题。 e.g:
android:theme="@style/Theme.AppCompat.Light"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
3.不要在Java文件中使用requestWindowFeature(Window.FEATURE_NO_TITLE);
,即不要隐藏TitleBar
。因为ActionBar
取代了它。
答案 1 :(得分:0)
您似乎试图在ActionBar
中使用Activity
,这是您获得IllegalStateException
的原因。
按照android:theme="@style/ThemeAppCompat.Light"
stacktrace
Exception