Android UI ActionBar功能-自动隐藏 Action Bar

来源:互联网 发布:把mac照片怎么传邮箱 编辑:程序博客网 时间:2024/06/06 07:40

为了使ActionBar不影响Activity的布局内容,我们还可以设置ActionBar,将其设置为透明,并且让Activity是头部自动空出一个ActionBar的空间:


官方文档:http://wear.techbrood.com/training/basics/actionbar/overlaying.html#EnableOverlay

在应用程序里面,我们添加了一个背景:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    tools:context=".MainActivity" ><ImageView android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@drawable/bg2"/></RelativeLayout>
然后自定义一个主题values/themes.xml,继承自Theme.Holo

<?xml version="1.0" encoding="utf-8"?><resources xmlns:android="http://schemas.android.com/apk/res/android">    <style name="CustomActionBarTheme" parent="@android:style/Theme.Holo">        <item name="android:windowActionBarOverlay">true</item>    </style></resources>
这样就可以实现ActionBar是透明效果:

让其背景让出一个ActionBar的位置 ,在Activity布局文件中让其android:paddingTop="?android:attr/actionBarSize"

然后查看效果:



0 0
原创粉丝点击