仿IOS透明通知栏(仅支持4.4以上版本)

来源:互联网 发布:手机淘宝怎么看好友 编辑:程序博客网 时间:2024/06/11 04:40

从4.4开始,Google为Android增加了透明状态栏和导航栏的功能,只需要加入少量代码就可以实现。如图:


在Activity的布局文件父View中添加属性:android:fitsSystemWindows="true"android:clipToPadding="true"即可。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:custom="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fitsSystemWindows="true"    android:clipToPadding="true"    android:background="#ffe5ff3e">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical">        <TextView            android:layout_width="match_parent"            android:layout_height="match_parent"            android:padding="16dp"            android:textSize="18sp"            android:text="@string/mytext" />    </LinearLayout></ScrollView>

如果不想要ActionBar,可以在AndroidManifest.xml或者Activity中去除,就得到上图效果。但是,透明通知栏只支持4.4以上的系统,在4.4以下还是会显示默认的通知栏。


如果希望修改通知栏颜色,可以参考Github大牛的Demo:

https://github.com/jgilfelt/SystemBarTint

其中的library只有一个SystemBarTintManager类,可以拷贝到自己的工程中使用,这样就不用依赖那个library了。

还可以参考这篇博文:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1117/1992.html

0 0
原创粉丝点击