Android UI ActionBar功能-自定义 Action Bar 样式

ActionBar的样式官方提供了三种:

Theme.Holo 

Theme.Holo.Light

Theme.Holo.Light.DarkActionBar


但不仅仅是这三种,我们还可以自己定义ActionBar的样式:

官方帮助文档地址:http://wear.techbrood.com/training/basics/actionbar/styling.html

比如让ActionBar显示一个纯色的背景图片:






首先导入文件:


他是一个点9PNG类型的文件,可以使中间无限伸展而不变型,在AndroidUI 布局动画-点九PNG技术 中有说明;

然后在values/下新建一个themes.xml文件,自定义ActionBar样式:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomActionBarTheme"  parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_background</item>
    </style>
</resources>
注:自定义的ActionBar必须继承自官方默认提供的三种主题中的一种;

然后在AndroidManifest.xml文件中将应用程序的主题更改为我们自定义的主题:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomActionBarTheme" >



posted @ 2015-10-04 22:18  Bodi  阅读(446)  评论(0编辑  收藏  举报