5

我无法通过 style.xml 更改 ActionBar 标题颜色(通过使用ActionBarCompat)(不是以编程方式)

样式.xml

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:windowBackground">@color/background_window</item>
        <!-- <item name="windowBackground">@color/background_window</item> -->
        <!-- <item name="android:actionBarStyle">@style/ActionBarStyle</item> -->

        <item name="actionBarStyle">@style/MyActionBar</item>

    </style>


 <style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:icon">@drawable/ic_launcher</item>
        <item name="android:background">#FF666666</item>
        <item name="icon">@drawable/ic_launcher</item>
        <item name="background">@color/abbackground_col</item>
        <item name="titleTextStyle">@style/MyActionBarTitleText</item>
    </style>


 <style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/actionBarText</item>
    </style>

</resources>

颜色.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="background_window">#FF4500</color>
    <color name="abbackground_col">#FF4500</color>
    <color name="actionBarText">#FF4500</color>
</resources>

清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.app.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

活动

import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.widget.TextView;

    public class MainActivity extends ActionBarActivity {
    ActionBar ab;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

        //  getActionBar().setDisplayHomeAsUpEnabled(true);

             ab = getSupportActionBar();
                ab.setTitle("Test");
    //          ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0099cc")));
                ab.setDisplayShowTitleEnabled(false);
                ab.setDisplayShowTitleEnabled(true);

            //    int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
          //      TextView yourTextView = (TextView)findViewById(titleId);
                yourTextView.setTextColor(Color.GREEN);
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

    }
4

1 回答 1

2

替换您的代码:

 <style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/actionBarText</item>
</style>

有了这个:

 <style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#ffffff</item>
</style>
于 2013-10-11T12:34:53.447 回答