制作我的第一个应用程序。创建之后我尝试将其设为全屏。它说“不幸的是你的应用程序已被停止。”
Android清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nirmal.projectfullscreen">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
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>
MainActiviy.java
package com.example.nirmal.projectfullscreen;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
logcat的
03-25 22:05:14.257 5289-5289/com.example.nirmal.projectfullscreen E/Trace: error opening trace file: No such file or directory (2)
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to resolve interface method 15038: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
03-25 22:05:14.427 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: VFY: unable to resolve interface method 15042: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
03-25 22:05:14.437 5289-5289/com.example.nirmal.projectfullscreen W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41f3c600)
03-25 22:05:14.437 5289-5289/com.example.nirmal.projectfullscreen E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nirmal.projectfullscreen/com.example.nirmal.projectfullscreen.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5578)
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:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
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.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:340)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:273)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.nirmal.projectfullscreen.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5066)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$600(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5578)
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:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: killProcess, pid=5289
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: dalvik.system.VMStack.getThreadStackTrace(Native Method)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.Thread.getStackTrace(Thread.java:599)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: android.os.Process.killProcess(Process.java:956)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:108)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
03-25 22:05:17.087 5289-5289/com.example.nirmal.projectfullscreen D/Process: dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
您正在使用AppCompatActivity
,因此您的主题应该继承Theme.AppCompat
。
您需要在此活动中使用Theme.AppCompat主题(或后代)。
使用此主题:
<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
在你的清单中:
android:theme="@style/AppFullScreenTheme"