请问Android的StatusBar是DecorView的一部分吗?

廿四桥明月夜 2017-06-11 09:54:56
一般,android的一个UI界面从上到下可以被分为状态栏、ToolBar、Content。那么状态栏是不是被绘制到DecorView中呢?
...全文
430 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
guwei4037 2017-06-11
  • 打赏
  • 举报
回复
Gif-Load-ReTry-Refresh:只需要一张Gif图,一行代码支持初次加载,重试加载,加载后再次刷新原理 :遍历View树,在Framelayout中动态插入和移除加载布局,与生命周期绑定,避免内存泄漏;功能 :目前支持在Activity,Fragment中使用(支持任何方式实现的沉浸式状态栏和透明状态栏);封装 :接口化调用,支持MVP结构中使用(View层implement LoadRetryRefreshListener接口,然后直接在Activity/Fragment传入this即可)。示例Activity中加载成功Activity中加载失败在Activity中加载成功,然后再次加载刷新在Activity中加载失败,然后重试加载,加载成功后刷新加载Fragment中加载成功Fragment中加载失败在Fragment中加载成功,然后再次加载刷新在Fragment中加载失败,然后重试加载,加载成功后刷新加载使用   初步配置引入配置属性示例代码在Activity中使用1、注册2、开始加载3、加载结果回调4、解除绑定布局代码(勿遗漏第4步,防止内存泄漏)在Fragment中使用1、注册2、开始加载3、加载结果回调4、解除绑定布局代码(勿遗漏第4步,防止内存泄漏)反馈与建议初步配置引入Step 1. Add it in your root build.gradle at the end of repositories:allprojects { repositories { ... maven { url 'https://jitpack.io' } } }Step 2. Add the dependencydependencies {         compile 'com.github.NoEndToLF:Gif-Load-ReTry-Refresh:1.1.2' }配置属性方法参数作用setGifR.drawable.*加载页面的Gif图setBackgroundColorR.color.*加载页面整体背景颜色setBtnNormalColorR.color.*加载页面按钮未按下时的颜色setBtnPressedColorR.color.*加载页面按钮按下时的颜色setBtnBorderColorR.color.*加载页面按钮边框的颜色setBtnTextColorR.color.*加载页面按钮文字的颜色setBtnRadiusFloat加载页面按钮的圆角弧度setBtnTextString加载页面按钮的显示文字setLoadTextString正在加载中的提示文字setLoadAndErrorTextColorR.color.*加载页面的提示文字和加载失败提示文字的颜色示例代码,建议在 Application的 onCreate中进行初始化LoadRetryRefreshConfig config=new LoadRetryRefreshConfig();         config.setBackgroundColor(R.color.white);         config.setBtnNormalColor(R.color.blue_normal);         config.setBtnPressedColor(R.color.blue_press);         config.setBtnBorderColor(R.color.oringe_normal);         config.setBtnRadius(10f);         config.setBtnText("点击重新加载");         config.setLoadText("测试加载2秒钟...");         config.setBtnTextColor(R.color.white);         config.setLoadAndErrorTextColor(R.color.gray);         config.setGif(R.drawable.zhufaner);                 LoadReTryRefreshManager.getInstance().setLoadRetryRefreshConfig(config);在 Activit中使用布局中,请在 Toolbar下的需要加载的内容最外层套一层 FrameLayout(为何需要这样做),如:android:layout_width="match_parent"     android:layout_height="match_parent"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:orientation="vertical"     xmlns:android="http://schemas.android.com/apk/res/android">     <android.support.v7.widget.Toolbar         app:contentInsetStart="0dp"         android:layout_width="match_parent"         android:layout_height="?attr/actionBarSize"         android:gravity="center_vertical"         android:id="@ id/toolbar"         android:background="@color/color_toolbar"         >         <FrameLayout             android:layout_width="match_parent"             android:layout_height="match_parent">                          **********************************             **********************************             你的内容布局,如Linearlayout等            **********************************             **********************************                           </FrameLayout></LinearLayout>代码中方法简介方法参数作用registerActivity,LoadRetryRefreshListener注册startLoadActivity开始加载unRegisterActivity解除绑定onLoadSuccessActivity,ShowRefreshViewListener关闭加载View和刷新时的Dialog、下拉刷新等onLoadFailed  Activity,String,ShowRefreshViewListener显示加载失败原因,关闭加载View和刷新时的Dialog、下拉刷新等1、注册,一般在 onCreate中调用LoadReTryRefreshManager.getInstance().register(this, new LoadRetryRefreshListener() {                       @Override             public void loadAndRetry() {                         //执行你的网络请求             //dosomething();             }            @Override             public void showRefreshView() {                         //显示你刷新时的加载View,如Dialog,下拉刷新等                              }         });2、开始加载,无需判断是初次加载还是刷新,已自动进行判断,只需要在想要加载或刷新的地方直接调用(加载失败重试加载已封装到 Button事件中)LoadReTryRefreshManager.getInstance().startLoad(this);3、加载结果回调,在你的请求成功和失败的回调中加入加载结果回调@Override             public void onSuccess(Integer value) {             //加载成功你要做的事.....                              //加载结果回调                 LoadReTryRefreshManager.getInstance().onLoadSuccess(FailedActivity.this,                  new ShowRefreshViewListener() {                     @Override                     public void colseRefreshView() {                      //关闭你的刷新View,如Dialog,下拉刷新等                       }                 });             }             @Override             public void onFailed(Throwable e) {             //加载失败你要做的事.....                              //加载结果回调                 LoadReTryRefreshManager.getInstance().onLoadFailed(FailedActivity.this,                  e.getMessage(), new ShowRefreshViewListener() {                     @Override                     public void colseRefreshView() {                        //关闭你的刷新View,如Dialog,下拉刷新等                     }                 });             }4、解除绑定,可以直接写在 BaseActivity的 onDestory方法中,会自动判断然后进行解绑Override     protected void onDestroy() {                 super.onDestroy();                  LoadReTryRefreshManager.getInstance().unRegister(this);     }在 Fragment中使用布局中,同 Activity中使用一致,请在 Toolbar下的需要加载的内容最外层套一层 FrameLayout(为何需要这样做)代码中方法简介方法参数作用registerFragment,View,LoadRetryRefreshListener注册(View为Fragment在onCreateView中返回的View)startLoadFragment开始加载unRegisterFragment解除绑定onLoadSuccessFragment,ShowRefreshViewListener关闭加载View和刷新时的Dialog、下拉刷新等onLoadFailedFragment,String,ShowRefreshViewListener显示加载失败原因,关闭加载View和刷新时的Dialog、下拉刷新等1、注册,一般在 onCreateView中调用LoadReTryRefreshManager.getInstance().register(this, contentView,new LoadRetryRefreshListener() {             @Override             public void loadAndRetry() {             //执行你的网络请求             //dosomething();             }             @Override             public void showRefreshView() {             //显示你刷新时的加载View,如Dialog,下拉刷新等                              }         });2、开始加载,无需判断是初次加载还是刷新,已自动进行判断,只需要在想要加载或刷新的地方直接调用(加载失败重试加载已封装到 Button事件中)LoadReTryRefreshManager.getInstance().startLoad(this);3、加载结果回调,在你的请求成功和失败的回调中加入加载结果回调@Override             public void onSuccess(Integer value) {             //加载成功你要做的事.....                              //加载结果回调                 LoadReTryRefreshManager.getInstance().onLoadSuccess(FailedActivity.this,                  new ShowRefreshViewListener() {                     @Override                     public void colseRefreshView() {                      //关闭你的刷新View,如Dialog,下拉刷新等                       }                 });             }             @Override             public void onFailed(Throwable e) {             //加载失败你要做的事.....                              //加载结果回调                 LoadReTryRefreshManager.getInstance().onLoadFailed(FailedActivity.this,                  e.getMessage(), new ShowRefreshViewListener() {                     @Override                     public void colseRefreshView() {                        //关闭你的刷新View,如Dialog,下拉刷新等                     }                 });             }4、解除绑定,可以直接写在 BaseFragment的 onDestroyView方法中,会自动判断然后进行解绑@Override     public void onDestroyView() {         super.onDestroyView();         LoadReTryRefreshManager.getInstance().unRegister(this);     }为何必须在布局中套一层 FrameLayout目前为了在4.4,5.0,6.0,7.0及以上的版本中实现沉浸式状态栏或者是透明式状态栏的适配,实现方式主要在低版本中有所不同,有的是设置全屏然后给Toolbar加一个PaddingTop来留出StatusBar的高度,有的是设置全屏StatusBar透明,然后再动态插入一个大小一致的View来占位,达到设置状态栏颜色的目的,因此,如果单纯的在DecorView中来插入加载布局,难以控制加载页面的MarginTop,可能会遮盖到Toolbar,所以退而求其次,在布局中需要加载的部分包一层FrameLayout,再通过递归View树来找到需要添加加载布局的地方,进行动态插入,这样就不需要处理兼容沉浸式状态栏或者是透明式状态栏的适配造成的问题(当然如果有更好的想法,强烈欢迎Issues或者邮箱建议)

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧