透明状态栏

    private boolean isLmpOrAbove() {
        return Build.VERSION.SDK_INT >= 21;//Build.VERSION_CODES.LOLLIPOP;
    }
    
    //状态栏透明
    @TargetApi(19)
    private void setupTransparentSystemBarsForLmp() {
        // TODO(sansid): use the APIs directly when compiling against L sdk.
        // Currently we use reflection to access the flags and the API to set
        // the transparency
        // on the System bars.
        if (isLmpOrAbove()) {
            try {
                getWindow().getAttributes().systemUiVisibility |= (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
                
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                
                Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
                
                getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
                
                Method setStatusBarColorMethod = Window.class.getDeclaredMethod("setStatusBarColor", int.class);
                
                Method setNavigationBarColorMethod = Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
                
                setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
                
                setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
            } catch (NoSuchFieldException e) {
                Log.w("yfl", "NoSuchFieldException while setting up transparent bars");
            } catch (NoSuchMethodException ex) {
                Log.w("yfl", "NoSuchMethodException while setting up transparent bars");
            } catch (IllegalAccessException e) {
                Log.w("yfl", "IllegalAccessException while setting up transparent bars");
            } catch (IllegalArgumentException e) {
                Log.w("yfl", "IllegalArgumentException while setting up transparent bars");
            } catch (InvocationTargetException e) {
                Log.w("yfl", "InvocationTargetException while setting up transparent bars");
            } finally {
            }
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值