Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBar text color change while using ActionBarCompat

I'm failed change the ActionBar Title color (by using ActionBarCompat) by style.xml (not programatically)

style.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>

color.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>

Manifest.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>

activity

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;
        }

    }
like image 611
LOG_TAG Avatar asked Nov 02 '22 13:11

LOG_TAG


1 Answers

Replace your code :

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

with this one :

 <style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#ffffff</item>
</style>
like image 170
Zankhna Avatar answered Nov 15 '22 06:11

Zankhna