Android透明状态栏

Android透明状态栏只有在4.4之后有。

其中设置有两种方式:

1.

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
           getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
这种设置会使VIEW平移到上面去,可通过下面方法解决,在布局文件中设置(红字部分):


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:background="#ff0000"
    android:paddingTop="@dimen/activity_vertical_margin"
    <span style="color:#FF0000;">android:fitsSystemWindows="true"
    android:clipToPadding="true"</span>
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">
fitsSystemWindows:设置应用布局时是否考虑系统窗口布局;如果为true,将调整系统窗口布局以适应你自定义的布局。比如系统有状态栏,应用也有状态栏时。看你这个布局代码,恰恰是在定义标题栏样式,所以用到这行代码了。

clipToPadding了是否允许ViewGroup在padding中绘制,该值默认为true,即不允许.

2.在THEME中设置:


    android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor"
                android:theme="@android:style/Theme.Holo.Light.NoActionBar.TranslucentDecor"
                android:theme="@android:style/Theme.Holo.NoActionBar.TranslucentDecor"
三种都可以,如果你使用自定主题,只需在在 values-19 文件添加以下属性:

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">

            <!-- API 19 theme customizations can go here. -->
            <item name="android:windowTranslucentStatus">true</item>
            <item name="android:windowTranslucentNavigation">true</item>
        </style>




郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。