尝试全屏活动时应用崩溃

时间:2015-02-15 12:22:30

标签: android

您好我正在使用以下代码隐藏操作栏和全屏我的活动

android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"

但是使用这段代码我得到运行时错误,应用程序崩溃任何人都知道问题是什么?

logcat的:

       
E/AndroidRuntime(1081): FATAL EXCEPTION: main
E/AndroidRuntime(1081): Process: com.example.directmate, PID: 1081
E/AndroidRuntime(1081): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.directmate/com.example.directmate.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
E/AndroidRuntime(1081):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
E/AndroidRuntime(1081):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
E/AndroidRuntime(1081):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime(1081):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime(1081):     at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(1081):     at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(1081):     at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime(1081):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(1081):     at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(1081):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime(1081):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime(1081):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(1081): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
E/AndroidRuntime(1081):     at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
E/AndroidRuntime(1081):     at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
E/AndroidRuntime(1081):     at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
E/AndroidRuntime(1081):     at com.example.directmate.MainActivity.onCreate(MainActivity.java:22)
E/AndroidRuntime(1081):     at android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime(1081):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime(1081):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
E/AndroidRuntime(1081):     ... 11 more

3 个答案:

答案 0 :(得分:2)

这可能与您的活动扩展部分有关,您添加到清单中的代码需要扩展活动而不是 ActionbarActivity

答案 1 :(得分:0)

使用此代码

   public void onCreate(Bundle savedInstanceState)
 {
 super.onCreate(savedInstanceState);
 requestWindowFeature(Window.FEATURE_NO_TITLE);
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

 setContentView(R.layout.main);
 }

答案 2 :(得分:0)

您正在使用应用中的操作栏并将主题设置为无操作栏。所以请同时同步。