直播app源码,状态栏和导航栏设置成透明状态

2022/3/1 17:24:56

本文主要是介绍直播app源码,状态栏和导航栏设置成透明状态,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

直播app源码,状态栏和导航栏设置成透明状态实现的相关代码

设置页面透明,使用主题

注册activity设置主题

 

 <style name="TranslucentNoActionBarTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>

设置状态栏和导航栏透明

直接调用下面方法,传当前activity即可

 

public void setNavAndStatusBarTransparent(Activity activity) {
        if (activity == null) {
            return;
        }
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                Window window = activity.getWindow();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    if (window != null) {
                        View decorView = window.getDecorView();
                        //两个 flag 要结合使用,表示让应用的主体内容占用系统状态栏的空间
                        int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
                        decorView.setSystemUiVisibility(option);
                        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                        window.setStatusBarColor(Color.TRANSPARENT);
                        //导航栏颜色也可以正常设置
                        window.setNavigationBarColor(Color.TRANSPARENT);
                    }
                } else {
                    if (window != null) {
                        WindowManager.LayoutParams attributes = window.getAttributes();
                        if (attributes != null) {
                            int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
                            int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
                            attributes.flags |= flagTranslucentStatus;
                            attributes.flags |= flagTranslucentNavigation;
                            window.setAttributes(attributes);
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

 

设置activity点击事件透传

注意要在onCreate方法的setContenView前添加如下代码

 

//设置activity点击透传
  WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
  layoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    

       

以上就是 直播app源码,状态栏和导航栏设置成透明状态实现的相关代码,更多内容欢迎关注之后的文章

 



这篇关于直播app源码,状态栏和导航栏设置成透明状态的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程