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

Theme.Holo 

Theme.Holo.Light

Theme.Holo.Light.DarkActionBar


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

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

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

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



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


首先导入文件:

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

他是一个点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" >



相关文章:

  • 2022-12-23
  • 2021-12-29
  • 2021-04-17
  • 2021-09-15
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
猜你喜欢
  • 2021-05-17
  • 2021-06-15
  • 2021-06-27
  • 2021-10-31
  • 2021-08-28
  • 2021-07-27
  • 2021-12-10
相关资源
相似解决方案