Cambiar el color del Título de la Barra de Acciones


Mi código es el siguiente y mientras funciona ( cuando cambio el Tema principal a Tema.Sherlock o Theme.Sherlock.Enciende el Tema que hace cambia) no cambia el color del título.

El código es más o menos el mismo que aquí

Código:

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

<style name="MyTheme" parent="@style/Theme.Sherlock">
 <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item>
 <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
     <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title" >
     <item name="android:textColor">#FF0000</item>
</style>

</resources>
Author: Community, 2013-04-26

7 answers

He cambiado el color del título de esta manera

actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));
 48
Author: MilapTank,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-21 11:01:17

Del sitio de ActionBarSherlock de Jake Wharton:

Atributos reflejados

Debido a limitaciones en el sistema de tematización de Android cualquier tema las personalizaciones deben declararse en dos atributos. Normal los atributos con prefijo android aplican el tema a la barra de acciones nativa y los atributos no fijos son para la implementación personalizada.

Tuvo que cambiar MyTheme.actionBarStyle a:

   <style name="MyTheme.ActionBarStyle" parent="@style/Widget.Sherlock.ActionBar">
     <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
     <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
   </style>

Ahora el color del texto del título ha cambiado.

 36
Author: mt0s,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-05 14:06:29

Use el código inferior para proporcionar un color diferente al texto de la barra de acción y al fondo de la barra de acción solo use el tema inferior en el manifiesto contra la actividad en la que desea obtener la salida:)

 <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:titleTextStyle">@style/TitleBarTextColor</item>
        <item name="android:background">YOUR_COLOR_CODE</item>
    </style>

    <style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">YOUR_COLOR_CODE</item>
    </style>
 13
Author: Android is everything for me,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-21 08:43:40

Probé todos los métodos anteriores, no funcionó para mí.Acabo de lograr a través de código a continuación..

Spannable text = new SpannableString(actionBar.getTitle());
text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
actionBar.setTitle(text);
 6
Author: Raja Jawahar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-12 13:09:55

La forma más sencilla que funcionó para mí es agregar lo siguiente en el estilo del tema:

<item name="android:textColorPrimary">@color/orange_dark</item>
 4
Author: user846316,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-30 19:58:12

A tu estilo.xml en la carpeta valores esto cambiará el color de la barra de acciones.. Reemplace #666666 con su código de color seleccionado para el color de fondo del título y reemplace #000000 para el color del texto del título.

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/NewActionBar</item>
</style>

<style name="NewActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/TitleBarTextColor</item>
<item name="android:background">#666666</item>
</style>
<style name="TitleBarTextColor" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Menu">
    <item name="android:textColor">#000000</item>
</style>

Entonces no te olvides de editar tu archivo de manifiesto - > android:theme="@style/NewTheme"

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/NewTheme" >
    <activity
        android:name="com.nearby.welcome.Splash"
        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>
 2
Author: Jesmeen Hoque,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-03 07:41:29

Si está tratando de cambiar el texto del título donde tiene una barra de herramientas personalizada, intente agregar app:titleTextColor a la barra de herramientas de la siguiente manera:

 <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:titleTextColor="@color/colorWhite" />
 1
Author: Joe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-23 05:28:02