gpt4 book ai didi

android - 尝试使用 AppCompat v21 实现工具栏

转载 作者:行者123 更新时间:2023-11-29 15:57:26 27 4
gpt4 key购买 nike

我正尝试按照本指南使用 AppCompat v21 实现工具栏,http://antonioleiva.com/material-design-everywhere/但是我无法在 KitKat 或 Lollipop 上启动并收到相同的错误消息(如下)。我完全相信我已经正确设置了主题,但我被困在这一点上并且已经坚持了一天多。我没有成功搜索解决方案,所以现在我正在寻求帮助。谢谢!

> 11-29 06:08:46.892  29771-29771/com.chaoticearth.chaoticearth E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.ce.ce, PID: 29771
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ce.ce/com.ce.ce.DrawerActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
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:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
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.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at com.ce.ce.BaseActivity.onCreate(BaseActivity.java:16)
at com.ce.ce.DrawerActivity.onCreate(DrawerActivity.java:92)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5146)
            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:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at dalvik.system.NativeStart.main(Native Method)

这是我的/res/values/themes.xml

<resources>

<style name="CETheme" parent="AppTheme" ></style>
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:colorPrimaryDark">@color/MidnightBlue</item>
<item name="android:colorAccent">@color/LightYellow</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>

</style>

这是我的/res/values-v21/themes.xml

<?xml version="1.0" encoding="utf-8"?>

    <item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>

<item name="android:colorPrimary">@color/ChaosBlue</item>
<item name="android:colorPrimaryDark">@color/MidnightBlue</item>
<item name="android:colorAccent">@color/LightYellow</item>
<item name="android:statusBarColor">@color/ChaosBlue</item>

</style>

这是我的 DrawerActivity.java 中抛出错误的 fragment :

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setActionBarIcon(R.drawable.ic_drawer);

还有一段来自被调用的 BaseActivity.java 的 fragment :

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResource());
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}

最后是我的 AndroidManifest.xml 中的一个 fragment

<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/CETheme"
android:name="android.support.multidex.MultiDexApplication">

最佳答案

我终于找到了原因,在我的 AndroidManifest 中我为我的 DrawerActivity 设置了一个主题,这导致了错误。

关于android - 尝试使用 AppCompat v21 实现工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27202239/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com