如果我不删除标题栏,我的应用程序将启动但是当我这样做时它会在它开始时崩溃。
这是我到目前为止的代码。
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.v1.solitare"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="com.v1.solitare.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
请以任何可能的方式提供帮助。我今天刚刚用Eclipse学习了Android编码,而且我很陌生。
编辑:我想我发现了LogCat错误:
04-02 22:06:28.986: E/AndroidRuntime(28352): FATAL EXCEPTION: main
04-02 22:06:28.986: E/AndroidRuntime(28352): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.v1.solitare/com.v1.solitare.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.app.ActivityThread.access$700(ActivityThread.java:165)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.os.Looper.loop(Looper.java:137)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.app.ActivityThread.main(ActivityThread.java:5455)
04-02 22:06:28.986: E/AndroidRuntime(28352): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 22:06:28.986: E/AndroidRuntime(28352): at java.lang.reflect.Method.invoke(Method.java:525)
04-02 22:06:28.986: E/AndroidRuntime(28352): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-02 22:06:28.986: E/AndroidRuntime(28352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-02 22:06:28.986: E/AndroidRuntime(28352): at dalvik.system.NativeStart.main(Native Method)
04-02 22:06:28.986: E/AndroidRuntime(28352): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
04-02 22:06:28.986: E/AndroidRuntime(28352): at com.v1.solitare.MainActivity.onCreate(MainActivity.java:18)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.app.Activity.performCreate(Activity.java:5372)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
04-02 22:06:28.986: E/AndroidRuntime(28352): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
04-02 22:06:28.986: E/AndroidRuntime(28352): ... 11 more
答案 0 :(得分:19)
ActionBarActivity
假设您使用ActionBar
,而Theme.NoTitleBar
主题删除了ActionBar(因为它是新设备上标题栏的一部分而ActionBarActivity
假设您是使用Theme.AppCompat
主题来控制ActionBar的样式。
如果你没有动作栏可以改变你的活动以扩展FragmentActivity
,尽管Android design docs是使你的应用感觉像Android应用程序的关键组件(尽管有些会说游戏有更多的回旋余地。)