ActionBar text color

后端 未结 24 2555
日久生厌
日久生厌 2020-11-22 05:31

how can I change the text color of the ActionBar? I\'ve inherited the Holo Light Theme, I\'m able to change the background of the ActionBar but I don\'t find out what is the

相关标签:
24条回答
  • 2020-11-22 06:10

    Found the way to do it nicely without creating your own layout on API >= 21.

    It will only colorize texts and control drawables inside the action bar.

    Hope it will be useful for someone.

    <!--Material design primary colors-->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:navigationBarColor">@color/primary_dark</item>
        <item name="actionBarTheme">@style/AppBaseTheme.Toolbar</item>
    </style>
    
    <!--Action bar-->
    <style name="AppBaseTheme.Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
        <item name="android:textColorPrimary">@color/action_bar_text</item>
        <item name="colorControlNormal">@color/action_bar_text</item>
    </style>
    
    0 讨论(0)
  • 2020-11-22 06:11

    Setting a HTML string on the action bar doesn't work on the Material theme in SDK v21+

    If you want to change it you should set the primary text color in your style.xml

    <resources>
        <!-- Base application theme. -->
        <style name="AppTheme" parent="android:Theme.Material.Light">
            <!-- Customize your theme here. -->
            <item name="android:textColorPrimary">@color/actionbar-text-color</item>
        </style>
    </resources>    
    
    0 讨论(0)
  • 2020-11-22 06:14

    just put this in your thme style.

    <item name="android:textColorPrimary">@color/yourcolor</item>

    0 讨论(0)
  • 2020-11-22 06:14

    For Android 5 (lollipop) you will have to use android:actionBarPopupTheme to set the textColor for the overflow menu.

    0 讨论(0)
  • 2020-11-22 06:14
    <android.support.v7.widget.Toolbar
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@color/color_primary"
      android:theme="@style/GalaxyZooThemeToolbarDarkOverflow"
      app:popupTheme="@style/Theme.AppCompat.NoActionBar" />
    
    
    <style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
      <!-- android:textColorPrimary is the  color of the title text
           in the Toolbar, in the Theme.AppCompat theme:  -->
      <item name="android:textColorPrimary">@color/abc_primary_text_material_light</item>
     
      <!-- android:textColorPrimaryInverse is the  color of the title
           text in the Toolbar, in the Theme.AppCompat.Light theme:  -->
      <!-- <item name="android:textColorPrimaryInverse">@color/abc_primary_text_material_light</item> -->
     
      <!-- android:actionMenuTextColor is the color of the text of
            action (menu) items in the Toolbar, at least in the
            Theme.AppCompat theme.
            For some reason, they already get the textColorPrimary
            when running on API 21, but not on older versions of
            Android, so this is only necessary to support older
            Android versions.-->
            <item name="actionMenuTextColor">@color/abc_primary_text_material_light</item>
      <!-- android:textColorSecondary is the color of the menu
           overflow icon (three vertical dots) -->
      <item name="android:textColorSecondary">@color/abc_secondary_text_material_light</item>
     
      <!-- This would set the toolbar's background color,
            but setting this also changes the popup menu's background,
            even if we define popupTheme for our <Toolbar> -->
      <!-- <item name="android:background">@color/color_primary</item> -->
    </style>
    
    
    **Reference:**
    [https://www.murrayc.com/permalink/2014/10/28/android-changing-the-toolbars-text-color-and-overflow-icon-color/][1]
    
    0 讨论(0)
  • 2020-11-22 06:15

    i have done with simple one line code

    actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBartitle </font>"));
    
    0 讨论(0)
提交回复
热议问题