ActionBar总结2_自定义action bar的样式

2014-11-24 11:54:00 · 作者: · 浏览: 1

例子见资源(不需要资源积分)

主要内容:

    Customize the Background

    更改action bar的字体颜色

    Customize the Tab Indicator

    Overlaying the Action Bar

Customize the Background

显示效果图:
enter image description here

实现:

    在styles中定义用于activity的theme,并覆盖actionBarStyle的属性,

        

      覆盖actionBarStyle的background属性值。

          
          
          
      在AndroidManifest.xml的activity标签中指定theme
          
          
          
          

      如果使用的是分离的action bar,你应该指定 backgroundStacked,backgroundSplit属性来指定背景。


      更改action bar的字体颜色


      显示效果图:
      enter image description here
      实现:

      为了修改action bar的文本字体颜色,你需要覆盖各个不同文本的属性值
      (action bar的标题,Action bar tabs,Action buttons)< http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PHN0cm9uZz48ZW0+YWN0aW9uIGJhcrXEserM4qO6IKOodGhlbWUgLT4gYWN0aW9uQmFyU3R5bGUgLT4gdGl0bGVUZXh0U3R5bGUgLT4gdGV4dENvbG9yIKOpPC9lbT48L3N0cm9uZz48L3A+CjxwcmUgY2xhc3M9"brush:java;">1.创建titleTextStyle指定textColor属性

          
          
          
          
          
      2.创建actionBarStyle指定titleTextStyle,
           
          
          
      3.定义用于activity的theme,并覆盖actionBarStyle的属性
           
          
          
      Action bar tabs: 定义用于activity的theme,并覆盖actionBarTabTextStyle的属性
          
          
          
      
          

      Action buttons: 定义用于activity的theme,并覆盖actionMenuTextColor的属性

          

      最后,在activity中指定theme


      Customize the Tab Indicator


      效果图:
      enter image description here
      为了实现当用户选择tab时,背景会发生变化,来表明用户选择了那一个tab

        实现:

        .创建actionBarTabStyle并覆盖background属性,background应该指向一个状态列表的drawable。

            
             
            
        
            
             
            
             
                
              
                
              
            
             

          定义用于activity的theme,并覆盖actionBarTabStyle的属性

                
              

            AndroidManifest.xml中指定theme


            Overlaying the Action Bar


            效果:
            enter image description here
            实现:
            只要开启overlay模式就可以了,也就是说android:windowActionBarOverlay设置成true


                
                
                   
                 

            在什么情况下使用?
            就是在有用户交互时,我们可能会隐藏或者显示action bar,然而这样会造成,这会导致你的activity
            重新计算和重绘布局,根据新的尺寸,为了避免这种情况,你就可以开启overlaymode。

            action bar总结都是基于android 3.0,为了支持低版本的设备,可以参阅“官方资料链接”的内容。

            官方资料链接:
            action bar1
            action bar2