android界面之沉浸式全屏等状态栏标题栏全解析

前言

比较常用的android应用界面有Fragment+Tab,例如微信,支付宝,QQ等等。因此对应于不同的tab切换,我们常常需要显示不同的状态栏、标题栏、ActionBar等等。本文就写一写状态栏、标题栏、ActionBar的显示与隐藏。

先贴出效果图:
android界面之沉浸式全屏等状态栏标题栏全解析_第1张图片
注意观察标题栏的变化。

实现方式:
显示标题的代码:

 private void add() {
        WindowManager.LayoutParams attributes = getActivity().getWindow().getAttributes();
        //清除flag
        attributes.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //添加flag
        attributes.flags |= (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION|WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getActivity().getWindow().setAttributes(attributes);
    }

去除标题栏的代码:

private void clear() {
        WindowManager.LayoutParams attributes = getActivity().getWindow().getAttributes();
        //清除flag
        attributes.flags &= (~(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION));
        //添加flag
        attributes.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        getActivity().getWindow().setAttributes(attributes);

    }

实现原理

这个留待以后再写,由于牵扯到源码分析,所以分析起来较为费时。后续有时间将这些内容补上。
先贴出一下相关的源码分析的文章,供参考:
Android触摸屏事件派发机制详解与源码分析三(Activity篇)

Android应用setContentView与LayoutInflater加载解析机制源码分析

你可能感兴趣的:(学习日记)