码迷,mamicode.com
首页 > 移动开发 > 详细

Android ActionBar自定义

时间:2015-03-07 22:40:49      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:

1.设置action bar的背景色 

第一种方式:getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ActionBarBackground));

ActionBarBackground 为定义在values/colors.xml

colors.xml

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

此种方法特点:简单方便,但必须在代码中设置,若不同activity公用同一个actionbar样式,则不利于复用 。 so, 参考第二种方式

 

第二种方式:由官方文档给出,通过设置主题的属性实现。(不同activity可复用)

具体做法: (以下方法适合3.0及以上,2.1及以上参考官方文档)

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:
<application android:theme="@style/CustomActionBarTheme" ... />
也可在建立项目后application或activity默认引用的主题样式文件styles.xml中直接修改添加
修改 <style name="AppBaseTheme" parent="@android:style/Theme.Holo"> 
或添加以上文件内容到styles.xml
actionbar_background可添加在colors.xml文件中

 

参考:http://blog.csdn.net/jwzhangjie/article/details/28852967

参考:http://blog.csdn.net/yueqinglkong/article/details/20876401

Android ActionBar自定义

标签:

原文地址:http://www.cnblogs.com/vagrant1991/p/4321011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!