fragment 实现沉浸(透明)状态栏

fragment代码:

public void onCreate(Bundle savedInstanceState) {
        // 判断Android>5.0才能使用
        if (Build.VERSION.SDK_INT >= 21) {
            // 好的当前活动的DecorView,在改变UI显示
            View decorView = getActivity().getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            // 使其状态栏呈现透明色
            getActivity().getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        super.onCreate(savedInstanceState);
    }

XML代码:

<FrameLayout 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:fitsSystemWindows="true"
    tools:context="xjj.com.luomusic.MainFragment">

    <pl.droidsonroids.gif.GifImageView
        android:id="@+id/music_gif"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:background="@drawable/g02">

    </pl.droidsonroids.gif.GifImageView>

    <ImageButton
        android:id="@+id/imgBt"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:animateLayoutChanges="true"
        android:visibility="invisible"
        android:layout_gravity="center"
        android:src="@drawable/pause_normal"/>

    <include layout="@layout/bottom"></include>

</FrameLayout>

 

但最终并未透明而是白色:

解决方法为删除其所有根布局的 android:fitsSystemWindows="true" 即可。

 

参照:

https://blog.csdn.net/qq_21265915/article/details/56272149

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值