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

后端 未结 20 2710
我寻月下人不归
我寻月下人不归 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:45

    Behavior of Actionbar can also be changed in APIs < 11

    See the Android Official Documentation for reference

    I am building an app with minSdkVersion = "9" and targetSdkVersion = "21" I changed the color of action bar and it works fine with API level 9

    Here is an xml

    res/values/themes.xml

    
    
        
        
    
        
        
    
    

    and set the color of actionbar you want

    res/values/colors.xml

    
    
        #fff //write the color you want here
    
    

    Actionbar color can also be defined in .class file, the snippet is

    ActionBar bar = getActionBar();
    bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));
    

    but this will not work with the API < 11, so styling the actionbar in xml is only way for API < 11

提交回复
热议问题