[英]why am I getting an Theme related error in android studio?
I am following a tutorial on how to make a launcher but for some reason when I add this line of code to my main activity with in the manifest the app crashes saying that my app has stopped 我正在关注如何制作启动器的教程,但是由于某种原因,当我将这行代码添加到我的主要活动中时,清单中的应用崩溃,表明我的应用已停止
android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar"
10-18 15:04:25.245 18122-18122/com.example.harrops.h20droidlauncher E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.harrops.h20droidlauncher, PID: 18122 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.harrops.h20droidlauncher/com.example.harrops.h20droidlauncher.HomeLayout}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5598) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 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:309) at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) at com.example.harrops.h20droidlauncher.HomeLayout.onCreate(HomeLayout.java:13) at android.app.Activity.performCreate(Activity.java:5459) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5598) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method)
if I remove the line of code the app runs just fine. 如果我删除代码行,则该应用程序运行正常。
Any help would be great. 任何帮助都会很棒。 Thanks as always in advance.
一如既往地感谢您。
To change the Background use: 要更改背景使用:
android:background=" "
You selected a wallpaper. 您选择了墙纸。
Try this instead 试试这个
android:background="#b6db49">
Below you have said that you want to use the theme. 在下面您已经说过要使用主题。 So you have to go in the manifest and edit the theme there which is
因此,您必须进入清单并在其中编辑主题
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar">
If You've begun Your project in Android Studio by default main activity extends ActionBarActivity
which requires the AppCompat
theme. 如果您已经开始在默认情况下在Android Studio中进行项目,则主活动将扩展
ActionBarActivity
,该动作需要AppCompat
主题。 Change the Java inheritance from ActionBarActivity
to Activity
and leave the theme in the manifest as it is. 将Java继承从
ActionBarActivity
更改为Activity
,并将主题保留在清单中。 Or use AppCompat
theme. 或使用
AppCompat
主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.