我使用導航抽屜從本教程如何更改操作欄背景和文本顏色
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的
12月7日至1日:57:38.882:E/AndroidRuntime(14690):致命異常:主 07-01 12:57:38.882:E/AndroidRuntime(14690): java.lang.RuntimeExcepti on:無法啓動活動 ComponentInfo {info.androidhive.slidingmenu/info.androidhive.slidingmenu.MainActivity}: android.util.AndroidRuntimeException:無法將自定義標題 與其他標題功能組合07-01 12:57:38.882: E/AndroidRuntime(14690): at 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):在 android.app.ActivityThread $ Hh andleMessage(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 $我thodAndArgsCaller.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 (Android)時間:12年07月12日原始方式12:57:38.882: E/AndroidRuntime(14690):致: Android。 util.AndroidRuntimeException:不能將自定義標題 與其他標題功能結合使用07-01 12:57:38.882:E/AndroidRuntime(14690): at 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):在 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270) 十二月七日至1日: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/A ndroidRuntime(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 more 07-01 12:57:38.892:E/AlarmManagerService(378): android_server_AlarmManagerService_set type = 3, 51461.572000000 12月7日至一日:57:38.892:V/AlarmManager(378):waitForAlarm結果:8月7日至一日 12:57:38.902:E/android.os.Debug(378):@Dumpstate> 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>
分享'AppTheme' xml代碼請 –
檢查[this](http://stackoverflow.com/a/19592911/1479511)或[this](http://stackoverflow.com/questions/5861661/actionbar-text -color/13333661#13333661) – NarendraJi
@DroidWormNarendra我添加此getActionBar()。的setTitle(Html.fromHtml( 「<字體顏色= \」 紅色\ 「>」 +的getString(R.string.app_name)+ 「」)) ;而仍然文字顏色是黑色 – Aditya