ActionBar自定义样式
2014-05-25 00:26
429 查看
最近项目需要应用到ActionBar,为了使ActionBar符合整个App的配色,需要自定义ActionBar的样式。当新建应用,你的style.xml应该是这样:
你需要对App的style进行扩展和定义,这里需要注意的是,你必须首先看一下App对应的AndroidManifest.xml文件。
其中ExploreActionBar.TabText中用到的一些9patch图片是从support-v7-appcompat包中拷贝出来。这里还纠结了下怎么对这些图片进行修改,发现如果会PS的同学修改很方便,直接用Photoshop打开改颜色就OK。还需要注意的是这里面的style的parent属性,你必须先了解需要定义的内容是受那个属性影响,然后再去Android的style中找到它的父style,然后定义自己的属性覆盖父style的。编辑完样式如下:
可以看到这个样式文件中主要有ExploreActionBar,ExploreActionBar.Title,ExploreActionBar.TabView,ExploreActionBar.TabText,分别代表了整个ActionBar,ActionBar标题,ActionBar选项卡,ActionBar选项卡文字的属性。需要注意的是android:backgroundStacked这个属性,它表示在选项卡单独显示时的背景色,横屏的时候你会发现选项卡会嵌入到ActionBar内,不再使用这个属性的背景。另外还有一个特殊的android:backgroundSplit属性,表示当ActionBar中Menu显示到屏幕底部作为Tab时的背景色,这里没有用到。
需要代码的可以到点击打开链接下载附件。
<span style="font-size:14px;"><resources> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> </resources></span>
你需要对App的style进行扩展和定义,这里需要注意的是,你必须首先看一下App对应的AndroidManifest.xml文件。
<span style="font-size:14px;"><uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" /></span>对应的你的Value下分为values,values-v11,values-v14这三个文件夹,由于我所写的应用是v14以上的SDK版本,所以为了让我自定义的style生效,我需要在values-v14下的style.xml中创建我的自定义样式。
<resources> <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <!-- API 14 theme customizations can go here. --> <item name="android:actionBarStyle">@style/MyActionBar</item> <item name="android:actionBarTabStyle">@style/MyActionBar.TabView</item> <item name="android:actionBarTabTextStyle">@style/MyActionBar.TabText</item> </style> <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar"> <item name="android:background">@color/c_actionbar_backgroud_soild</item> <item name="android:titleTextStyle">@style/MyActionBar.Title</item> <item name="android:backgroundStacked">@color/c_actionbar_backgroundstacked</item> </style> <style name="MyActionBar.Title" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title"> <item name="android:textColor">@color/c_actionbar_title_default</item> <item name="android:textSize">14sp</item> </style> <style name="MyActionBar.TabView" parent="@android:style/Widget.Ho 94d1 lo.Light.ActionBar.TabView"> <item name="android:background">@drawable/actionbar_tab_background</item> </style> <style name="MyActionBar.TabText" parent="@android:style/Widget.Holo.Light.ActionBar.TabText"> <item name="android:textColor">@color/c_actionbar_tab_title</item> <item name="android:textSize">14sp</item> </style> </resources>
其中ExploreActionBar.TabText中用到的一些9patch图片是从support-v7-appcompat包中拷贝出来。这里还纠结了下怎么对这些图片进行修改,发现如果会PS的同学修改很方便,直接用Photoshop打开改颜色就OK。还需要注意的是这里面的style的parent属性,你必须先了解需要定义的内容是受那个属性影响,然后再去Android的style中找到它的父style,然后定义自己的属性覆盖父style的。编辑完样式如下:
可以看到这个样式文件中主要有ExploreActionBar,ExploreActionBar.Title,ExploreActionBar.TabView,ExploreActionBar.TabText,分别代表了整个ActionBar,ActionBar标题,ActionBar选项卡,ActionBar选项卡文字的属性。需要注意的是android:backgroundStacked这个属性,它表示在选项卡单独显示时的背景色,横屏的时候你会发现选项卡会嵌入到ActionBar内,不再使用这个属性的背景。另外还有一个特殊的android:backgroundSplit属性,表示当ActionBar中Menu显示到屏幕底部作为Tab时的背景色,这里没有用到。
需要代码的可以到点击打开链接下载附件。
相关文章推荐
- 为SeekBar滑块设置固定值以及自定义Seekbar,progressbar样式
- html默认的样式
- Bootstrap--全局css样式之表单
- css3中边框的4种样式
- HTML 样式兼容不同设备类型
- Firefox高版本中alert样式问题
- 使用jquery自定义鼠标样式满足个性需求
- 【JS总结】——DOM操作表格和样式
- Html对话框三种样式
- jQuery的属性与样式之元素的数据存储
- Silverlight动态设置样式
- 如何让每个 WordPress 页面有不同的风格或者样式
- UITableView创建样式
- 设置弹出层样式
- Android Studio之 更改背景颜色及主题样式
- 修改 fileupload 样式
- android中listview的一些样式设置
- Windows Phone 三、样式和资源
- css折叠样式(3)――常用样式属性
- 关于ueditor上传图片后拖动图片自动添加style样式 手机端不能自适应问题