How do I change the background color of the ActionBar of an ActionBarActivity using XML?

后端 未结 20 2701
我寻月下人不归
我寻月下人不归 2020-11-22 01:09

Details:

I\'m extending ActionBarActivity.
Eclipse and SDK fully patched as of 2011-11-06.



        
相关标签:
20条回答
  • 2020-11-22 02:01

    On the Nexus 4 people this seems to make the color go grey.

    ActionBar bar = getActionBar(); // or MainActivity.getInstance().getActionBar()
    bar.setBackgroundDrawable(new ColorDrawable(0xff00DDED));
    bar.setDisplayShowTitleEnabled(false);  // required to force redraw, without, gray color
    bar.setDisplayShowTitleEnabled(true);
    

    (all credit to this post, but it is buried in the comments, so I wanted to surface it here) https://stackoverflow.com/a/17198657/1022454

    0 讨论(0)
  • 2020-11-22 02:02

    Use below code to provide different color to actionbar text and actionbar background just use below theme in manifest against the activity in which you want output :)

    <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>
    
    0 讨论(0)
  • 2020-11-22 02:02

    This worked for me, for AppCompatActivity,

        <item name="actionBarStyle">@style/BlackActionBar</item>
    </style>
    
    <style name="BlackActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
        <item name="background">@android:color/black</item>
        <item name="titleTextStyle">@style/BlackActionBarTitleTextStyle</item>
    </style>
    
    <style name="BlackActionBarTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:fontFamily">@font/cinzel_decorative</item>
    </style>
    
    0 讨论(0)
  • 2020-11-22 02:04

    Its very simple for those who are using API 21 or greater Use this code below

    for Dark ActionBar

    <resources>
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:background">@color/colorDarkGrey</item>
    </style>
    

    for_LightActionBar

    <resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.ActionBar">
        <item name="android:background">@color/colorDarkGrey</item>
    </style>
    
    0 讨论(0)
  • 2020-11-22 02:04

    Use this, it would work.

    ActionBar actionbar = getActionBar();
    actionbar.setBackgroundDrawable(new ColorDrawable("color"));
    
    0 讨论(0)
  • 2020-11-22 02:06
    getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.TabColor)));
    

    color.xml file:

    <resources> <color name="TabColor">#11FF00</color> </resources>`
    
    0 讨论(0)
提交回复
热议问题