【问题标题】:How to change the text color in Android Action bar如何更改 Android 操作栏中的文本颜色
【发布时间】:2016-03-09 20:37:32
【问题描述】:

您好,我需要帮助更改操作栏的文本颜色以下是我的 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>

【问题讨论】:

标签: android


【解决方案1】:

试试这个

<?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>

【讨论】:

    【解决方案2】:

    改变你的风格。

     <!-- 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>
    

    希望对你有帮助。

    【讨论】:

    • textColorPrimary 然后会改变其他地方的文本颜色,例如溢出弹出菜单
    【解决方案3】:

    您可以像这样简单地将颜色添加到您的字符串:

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

    【讨论】:

      【解决方案4】:

      在您的 .axml 中放置一个 RelativeLayout 以添加操作栏。在这里添加一个具有 android:textColor="#FFFFFF" 属性的 TextView。 (#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】:

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

        当您单击左侧的颜色时,它会打开调色板。而且您可以轻松更改它。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-07-11
          • 2023-03-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-07-31
          • 1970-01-01
          相关资源
          最近更新 更多