Android Actionbar Custom

Source: Internet
Author: User

1. Set the background color of the action bar

The first way: Getactionbar (). Setbackgrounddrawable (Getresources (). getdrawable (R.drawable.actionbarbackground));

Actionbarbackground for the definition in Values/colors.xml

Colors.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<drawable name= "Actionbarbackground" > #ED4026 </drawable>
</resources>

This method features: simple and convenient, but must be set in the code, if the different activity common with the same actionbar style, it is not conducive to reuse. So, refer to the second way

The second way: given by an official document, by setting the properties of the theme. (different activity can be reused)

Specific practices: (The following method is suitable for 3.0 and above, 2.1 and above reference official documents)

Res/values/themes.xml

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

Then apply Your theme to your entire app or individual activities:
span>
<application android:theme< Span class= "pun" >= "@style/customactionbartheme"  ... />        
  Modify  <style name= "Appbasetheme" parent= "@android: Style/theme.holo" >&NBSP; 
or add the above file contents to Styles.xml
Actionbar_background can be added to the Colors.xml file

Reference: http://blog.csdn.net/jwzhangjie/article/details/28852967

Reference: http://blog.csdn.net/yueqinglkong/article/details/20876401

Android Actionbar Custom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.