设定ActionBar的样式,是我们必须掌握的技能,在之前我们可能都需要一行一行的写代码,然后在模拟器上测试效果,但是现在我们有个一个很棒的工具来设定样式。设定ActionBar样式的工作从未如此简单过!

http://romannurik.github.io/AndroidAssetStudio/index.html

进入后我们就可以直接在可视化的界面中进行修改了,设定好后直接下载压缩包。复制到res目录下即可。最后要记得把Application或者Activity的主题修改为你做的主题名哦~

顺便补充一个设置ActionBar背景的方法:

getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.id.icon));

下面是我这个主题的style:styles_mycompattheme.xml(这里的文件是V14的,详细的请下载源码)

<?xml version="1.0" encoding="utf-8"?>
<!-- File created by the Android Action Bar Style Generator Copyright (C) 2011 The Android Open Source Project
Copyright (C) 2012 readyState Software Ltd Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--> <resources> <style name="Theme.Mycompattheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarItemBackground">@drawable/selectable_background_mycompattheme</item>
<item name="android:popupMenuStyle">@style/PopupMenu.Mycompattheme</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.Mycompattheme</item>
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Mycompattheme</item>
<item name="android:actionDropDownStyle">@style/DropDownNav.Mycompattheme</item>
<item name="android:actionBarStyle">@style/ActionBar.Solid.Mycompattheme</item>
<item name="android:actionModeBackground">@drawable/cab_background_top_mycompattheme</item>
<item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_mycompattheme</item>
<item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Mycompattheme</item> <!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">@style/Theme.Mycompattheme.Widget</item> </style> <style name="ActionBar.Solid.Mycompattheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/ab_background_textured_mycompattheme</item>
<item name="android:backgroundStacked">@drawable/ab_stacked_solid_mycompattheme</item>
<item name="android:backgroundSplit">@drawable/ab_background_textured_mycompattheme</item>
<item name="android:progressBarStyle">@style/ProgressBar.Mycompattheme</item>
</style> <style name="ActionBar.Transparent.Mycompattheme" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@drawable/ab_transparent_mycompattheme</item>
<item name="android:progressBarStyle">@style/ProgressBar.Mycompattheme</item>
</style> <!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Mycompattheme.Widget" parent="@style/Theme.AppCompat">
<item name="android:popupMenuStyle">@style/PopupMenu.Mycompattheme</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.Mycompattheme</item>
</style> </resources>

当然,如果你觉得你想修改Menu和Tab上面的字体,设置个颜色什么的。那么下面的设置一定可以满足你的需要。

更详细的定义可以参考:http://blog.csdn.net/gebitan505/article/details/12157027

这里定义了Tab中字体的大小和颜色,定义了Menu的字体的大小和颜色,定义了返回按钮和分割栏的图片。

部分代码如下,这个是在之前的代码中修改的。

    <style name="Theme.Mycompattheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

        <!-- 定义ActionBar左边小箭头的图片 -->
<item name="android:homeAsUpIndicator">@drawable/ic_search</item>
<!-- 设置ActionBar的高度 -->
<item name="android:actionBarSize">60dip</item>
<!-- 设置Menu的颜色 -->
<item name="android:actionMenuTextColor">#ff0000</item>
<!-- 设置Menu的字体样式 -->
<item name="android:actionMenuTextAppearance">@style/MyMenuTextStyle</item>
<!-- 设置ActionBar Tab字体的样式 -->
<item name="android:actionBarTabTextStyle">@style/MyTabTextStyle</item>
<!-- 定义Tab之间的分割线的图片 -->
<item name="android:actionBarDivider">@drawable/ic_search</item>     省略了由工具生成的代码…… </style> <!-- Menu的样式 -->
<style name="MyMenuTextStyle">
<item name="android:textSize">30sp</item>
</style> <!-- Tab字体的颜色、字体等样式 -->
<style name="MyTabTextStyle" parent="@style/Widget.AppCompat.Light.ActionBar.TabText">
<item name="android:textColor">#0000ff</item>
<item name="android:textSize">18sp</item>
</style>

至于定义actionbar上面的进度条样式的可以看这篇文章:http://www.myexception.cn/mobile/1356045.html

更加详细全面的ActionBar的样式的修改可以看这里:http://blog.csdn.net/guolin_blog/article/details/25466665 (推荐)

源码下载:http://download.csdn.net/detail/shark0017/7690915

低版本系统兼容的ActionBar(五)修改ActionBar的全套样式,从未如此简单过的更多相关文章

  1. 低版本系统兼容的ActionBar(一)设置颜色+添加Menu+添加ActionMode

        之前我一直用ActionBarSherlock这个开源项目来做ActionBar,因为它可以让低版本的设备也能用上ActionBar.但是在最新的SDK中Google提供了一个AppCompa ...

  2. 低版本系统兼容的ActionBar(二)ActionProvider+分离式ActionBar+分离式的ActionMode

           这篇文章主要讲的是在低版本兼容的ActionBar中实现自定义的ActionProvider,ShareActionProvider的使用方法,如何实现分离式ActionBar,外加在分 ...

  3. 低版本系统兼容的ActionBar(六)用Fragment+ViewPager+Tab实现快速导航

    Tab经常和Fragment结合使用,这一讲我们用3种方式来实现这种快捷导航. 0.重要的两个监听器 MyTabListener,这个我们之前已经接触过了 package com.kale.actio ...

  4. 低版本系统兼容的ActionBar(四)添加Tab+添加自定义的Tab视图+Fragment

    在ActionBar中添加Tab是很有用的技巧.在support V7库的支持下,我们几乎可以用和之前一样的方式来添加Tab,对于Tab来说,我们可以和MenuItem一样,给他定义自己的视图.我这里 ...

  5. 低版本系统兼容的ActionBar(七)自定义Actionbar标题栏字体

    这个自定义字体其实和ActionBar有关,但之前写AtionBar的时候没考虑到修改字体样式,今天看到一篇专门写这个的文章就贴上使用方式.╮(╯▽╰)╭,不得不说Actionbar的那个样式真是让人 ...

  6. 低版本系统兼容的ActionBar(三)自定义Item视图+进度条的实现+下拉导航+透明ActionBar

           一.自定义MenuItem的视图 custom_view.xml (就是一个单选按钮) <?xml version="1.0" encoding="u ...

  7. hyperscan在低版本系统应用问题

    编译环境:centos6.3 32位/64位 由于hyperscan使用许多C++11特性,在低版本系统gcc版本不能编译.后来发现在runtime时也就是hs_scan时只需要依赖libhs_run ...

  8. Android 高版本API方法在低版本系统上的兼容性处理

    Android 版本更替,新的版本带来新的特性,新的方法. 新的方法带来许多便利,但无法在低版本系统上运行,如果兼容性处理不恰当,APP在低版本系统上,运行时将会crash. 本文以一个具体的例子说明 ...

  9. 低版本Flume兼容高版本elasticsearch

    Flume更新比较慢,而elasticsearch更新非常快所以当涉及更换elasticsearch版本时会出现不兼容问题. apache-flume-1.6.0+elasticsearch1.5.1 ...

随机推荐

  1. HTML5练习4

    1.菜单条 主要代码 <!doctype html> <html> <head> <meta charset="utf-8"> &l ...

  2. synchronized和lock

    Synchronized  同步代码块 使用 monitorenter 和 moniterexit 指令实现, monitorenter指令插入到同步代码块的开始位置, moniterexit 指令插 ...

  3. Angular 快速学习笔记(1) -- 官方示例要点

    创建组件 ng generate component heroes {{ hero.name }} {{}}语法绑定数据 管道pipe 格式化数据 <h2>{{ hero.name | u ...

  4. shell编程快速入门及实战

    shell编程:对于hadoop程序员,通常需要熟悉shell编程,因为shell可以非常方便的运行程序代码. 1.shell文件格式:xxx.sh #!/bin/sh ---shell文件第一行必须 ...

  5. 005.Zabbix-Agent客户端安装

    一 安装Zabbix-Agent [root@imxhy ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-rel ...

  6. 001.NTP简介

    一 NTP简介 ntp服务器顾名思义就是时间同步服务器(Network Time Protocol),时间同步对于计划备份.入侵检测记录.分布式任务调度或者事务订单管理来说都是非常有必要的日常任务. ...

  7. csdn 音乐 怎么拦截 提交后的程序 csdn 栏目 音乐 csdn 添加 音乐

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha csdn 栏目 音乐 csdn 添加 音乐 ======= <embed src= ...

  8. 项目冲刺First

    First Sprint 1.各个成员在 Alpha 阶段认领的任务(由于后面小组的讨论,修改本阶段的任务安排,()内为新任务安排) 蔡振翼:管理员界面.书籍管理,图书归还,消息,退出功能(撰写博客) ...

  9. codevs 3022 西天收费站

    题目描述 Description 唐僧师徒四人终于发现西天就在眼前,但猴子突然发现前面有n个收费站(如来佛太可恶),在每个收费站用不同的方式要交的钱不同,输入每个收费站的每种方法收的钱,输出最少花的钱 ...

  10. BZOJ.4355.Play with sequence(线段树)

    题目链接 问题在于操作二.操作二可以拆分成:区间加\(C\).区间(对\(0\))取\(\max\). 注意到操作一的\(C\)都是非负数,即数列中不会出现负数,所以我们直接维护最小值和最小值出现的次 ...