我正在使用本教程中的导航抽屉
http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/
我试图从这个选定的答案中更改操作栏背景
但是当我运行我的应用程序应用程序崩溃并显示错误
清单
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="info.androidhive.slidingmenu.MainActivity"
android:label="@string/app_name" >
</activity>
<activity android:name="Login_Page"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
>
</activity>
<activity android:name="Register"></activity>
<activity android:name="SplashActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);
logcat的
07-01 12:57:38.882:E / AndroidRuntime(14690):致命异常:主要 07-01 12:57:38.882:E / AndroidRuntime(14690): java.lang.RuntimeException:无法启动活动 ComponentInfo {info.androidhive.slidingmenu / info.androidhive.slidingmenu.MainActivity}: android.util.AndroidRuntimeException:您无法组合自定义标题 与其他标题功能07-01 12:57:38.882:E / AndroidRuntime(14690): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970) 07-01 12:57:38.882:E / AndroidRuntime(14690):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995) 07-01 12:57:38.882:E / AndroidRuntime(14690):at android.app.ActivityThread.access $ 600(ActivityThread.java:128)07-01 12:57:38.882:E / AndroidRuntime(14690):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1161) 07-01 12:57:38.882:E / AndroidRuntime(14690):at android.os.Handler.dispatchMessage(Handler.java:99)07-01 12:57:38.882:E / AndroidRuntime(14690):at android.os.Looper.loop(Looper.java:137)07-01 12:57:38.882: E / AndroidRuntime(14690):at android.app.ActivityThread.main(ActivityThread.java:4517)07-01 12:57:38.882:E / AndroidRuntime(14690):at java.lang.reflect.Method.invokeNative(Native Method)07-01 12:57:38.882:E / AndroidRuntime(14690):at java.lang.reflect.Method.invoke(Method.java:511)07-01 12:57:38.882: E / AndroidRuntime(14690):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:993) 07-01 12:57:38.882:E / AndroidRuntime(14690):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)07-01 12:57:38.882:E / AndroidRuntime(14690):at dalvik.system.NativeStart.main(Native Method)07-01 12:57:38.882: E / AndroidRuntime(14690):引起: android.util.AndroidRuntimeException:您无法组合自定义标题 与其他标题功能07-01 12:57:38.882:E / AndroidRuntime(14690): 在 com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:245) 07-01 12:57:38.882:E / AndroidRuntime(14690):at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2701) 07-01 12:57:38.882:E / AndroidRuntime(14690):at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2921) 07-01 12:57:38.882:E / AndroidRuntime(14690):at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 07-01 12:57:38.882:E / AndroidRuntime(14690):at android.app.Activity.setContentView(Activity.java:1835)07-01 12:57:38.882:E / AndroidRuntime(14690):at info.androidhive.slidingmenu.MainActivity.onCreate(MainActivity.java:50) 07-01 12:57:38.882:E / AndroidRuntime(14690):at android.app.Activity.performCreate(Activity.java:4470)07-01 12:57:38.882:E / AndroidRuntime(14690):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053) 07-01 12:57:38.882:E / AndroidRuntime(14690):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934) 07-01 12:57:38.882:E / AndroidRuntime(14690):... 11更多07-01 12:57:38.892:E / AlarmManagerService(378): android_server_AlarmManagerService_set为type = 3,51461.572000000 07-01 12:57:38.892:V / AlarmManager(378):waitForAlarm结果:8 07-01 12:57:38.902:E / android.os.Debug(378):!@ Rollstate&gt; dumpstate -k -t -n -z -d -o / data / log / dumpstate_app_error
Style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="WindowTitleBackground">
<item name="android:background">@color/titlebackgroundcolor</item>
<item name="android:textColor">@color/titletextcolor</item>
</style>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
答案 0 :(得分:3)
在styles.xml
:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@color/titlebackgroundcolor</item>
<item name="android:titleTextStyle">@style/MyActionBar.Text</item>
</style>
<style name="MyActionBar.Text" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#FFFF00</item>
</style>
</resources>
删除这两行:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);
它适用于你。