android开发training之actionbar之3

装饰action bar


一、使用默认的action bar

Android theme有两种theme支持action bar


可以在<application> 中定义应用的全局theme也可以在<activity> 中单独定义一个activity的theme。例如:

<application android:theme="@android:style/Theme.Holo.Light" ... />

效果如下:


action bar是黑色而其余部分是light color使用Theme.Holo.Light.DarkActionBartheme.

当使用支持库时,用下面的方法:

When using the Support Library, you must instead use the Theme.AppCompat themes:


二、自己定制的action bar

Android3.0及以上:

像下面这样改变action bar的背景色:


res/values/themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/orange</item>
    </style>
</resources>

在整个app或某个activity中应用主题:

<application android:theme="@style/CustomActionBarTheme" ... />
android2.1以下就不指明怎么用了。

三、自定义action bar中文字。

实现如下效果:


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/orange</item>
        <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
    </style>


    <!-- ActionBar title text -->
    <style name="MyActionBarTitleText" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@color/actionbar_text</item>
    </style>
</resources>

android2.1以下就不指明怎么用了。

四、将action bar变成透明的效果,如下:


Android 3.0以上,自己定制的theme的父theme应该是Theme.Holo 例如:


<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo">
        <item name="android:windowActionBarOverlay">true</item>
    </style>
</resources>
但是会有一个问题,顶部的textview在action bar下面,用下面的方法解决。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?android:attr/actionBarSize">
    ...
</RelativeLayout>

http://download.csdn.net/detail/xliubaox/8304183  源代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值