如何更改Android操作栏中的文本颜色

时间:2016-03-09 11:50:39

标签: android

您好我需要帮助更改操作栏的文本颜色以下是我的style.xml。我需要将文本颜色更改为白色,包括设置图标。

    <resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" >

    </style>
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

String.xml源代码如下。

<resources>
    <string name="app_name">yebo</string>

    <string name="navigation_drawer_open">Open navigation drawer</string>
    <string name="navigation_drawer_close">Close navigation drawer</string>

    <string name="action_settings">Settings</string>

</resources>

6 个答案:

答案 0 :(得分:2)

试试这个

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  </style>

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

  <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/red</item>
  </style>
</resources>

答案 1 :(得分:1)

改变你的风格。

 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

在线下添加:

    <item name="actionMenuTextColor">Your Color Here</item>
    <item name="textColorPrimary">Your Color Here</item>
</style>

希望它有所帮助。

答案 2 :(得分:1)

您可以简单地将颜色添加到字符串中:

<string name="app_name"><![CDATA[<b><font color=#FFFFFF>yebo</b>]]></string>

答案 3 :(得分:0)

Valus / styles.xml使用colors.xml文件。按“控制”并单击@ color / colorPrimary时,它会显示colorPrimary的来源。哪个是colors.xml。在您的colors.xml文件中,您可以对其进行编辑。

Colors.xml

单击左侧的颜色时,将打开调色板。你可以轻松改变它。 Color palette

答案 4 :(得分:0)

在你的.axml中放一个RelativeLayout来添加动作栏。在这里添加一个TextView,其属性为android:textColor =&#34; #FFFFFF&#34;。 (#FFFFFF是白色的)。就这样:

<RelativeLayout
    android:id="@+id/titleBarLinearLayoutFrontPage"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="55dp"
    android:background="#696969">
    <TextView
        android:textColor="#FFFFFF"
        android:id="@+id/txtActionBarText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="My Action Bar"
        android:layout_gravity="center"
        android:clickable="true"
        android:layout_centerVertical="true"
        android:textSize="22dp"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="60dp"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

答案 5 :(得分:-1)

试试这个:

Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
toolbar.setTitle(R.string.app_name);
toolbar.setTitleTextColor(getResources().getColor(R.color.someColor));
setSupportActionBar(toolbar);