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

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

Details:

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



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

    Use this - http://jgilfelt.github.io/android-actionbarstylegenerator/

    Its an amazing tool that lets you customize your actionbar with a live preview.

    I tried the earlier answers but always had problems with changing other colors like the tabs and letters and spent hours tweaking stuff. This tool helped me get my design done in just a couple of minutes.

    Here's a screenshot of the tool

    All the best! :)

    0 讨论(0)
  • 2020-11-22 01:57

    When you are Extending Activity use following Code

    ActionBar actionbar = getActionBar();
    actionbar.setBackgroundDrawable(new ColorDrawable("color"));
    

    When you are Extending AppCompatActivity use following Code

    ActionBar actionbar = getSupportActionBar();
    actionbar.setBackgroundDrawable(new ColorDrawable("color"));
    
    0 讨论(0)
  • 2020-11-22 01:58

    Try this

    ActionBar bar = getActionBar();
    bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
    
    0 讨论(0)
  • 2020-11-22 01:58

    Use This code ..to change action bar background color. open "res/values/themes.xml" (if not present, create it) and add

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>
     <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_background</item>
    </style>
    

    Note : this code works for android 3.0 and higher versions only

    0 讨论(0)
  • 2020-11-22 01:59

    This code may be helpful

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
    </style>
    <style name="Theme.MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- customize the color palette -->
        <item name="colorPrimary">@color/material_blue_500</item>
        <item name="colorPrimaryDark">@color/material_blue_700</item>
        <item name="colorAccent">@color/material_blue_500</item>
        <item name="colorControlNormal">@color/black</item>
    
    </style>
    <style name="CardViewStyle" parent="CardView.Light">
        <item name="android:state_pressed">@color/material_blue_700</item>
        <item name="android:state_focused">@color/material_blue_700</item>
        <!--<item name="android:background">?android:attr/selectableItemBackground</item>-->
    </style>
    

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

    Direct add this line with your color code

    getSupportActionBar().setBackgroundDrawable(
        new ColorDrawable(Color.parseColor("#5e9c00")));
    

    not need to create ActionBar object every time...

    0 讨论(0)
提交回复
热议问题