我很确定当我向我的应用添加主题时问题就出现了。我做了一些改动而没有保存它所以我不完全确定。
我不断收到java运行时错误和一条消息,说我需要使用Theme.AppCompat主题(或后代)。如何在保持当前主题的同时做到这一点? (黑色,没有标题栏,全屏)我一直在学习开发大约一个星期,我很想知道如何解决这个问题。
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.crystalball"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:requiredForAllUsers="true">
<activity
android:name=".MainActivity"
android:label="string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</a`enter code here`ctivity>
</application>
</manifest>
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.crystalball.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="81dp"
android:layout_marginTop="44dp"
android:textSize="32sp" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="Enlighten me!" />
</RelativeLayout>
这是我的LogCat的副本:
03-20 10:55:27.369: E/AndroidRuntime(19650): FATAL EXCEPTION: main
03-20 10:55:27.369: E/AndroidRuntime(19650): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.crystalball/com.example.crystalball.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.app.ActivityThread.access$700(ActivityThread.java:165)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.os.Looper.loop(Looper.java:137)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.app.ActivityThread.main(ActivityThread.java:5455)
03-20 10:55:27.369: E/AndroidRuntime(19650): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 10:55:27.369: E/AndroidRuntime(19650): at java.lang.reflect.Method.invoke(Method.java:525)
03-20 10:55:27.369: E/AndroidRuntime(19650): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
03-20 10:55:27.369: E/AndroidRuntime(19650): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
03-20 10:55:27.369: E/AndroidRuntime(19650): at dalvik.system.NativeStart.main(Native Method)
03-20 10:55:27.369: E/AndroidRuntime(19650): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
03-20 10:55:27.369: E/AndroidRuntime(19650): at com.example.crystalball.MainActivity.onCreate(MainActivity.java:18)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.app.Activity.performCreate(Activity.java:5372)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
03-20 10:55:27.369: E/AndroidRuntime(19650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
03-20 10:55:27.369: E/AndroidRuntime(19650): ... 11 more
感谢您提供的任何帮助。