Android开发自定义状态栏

   Window window = this.getWindow();  
   ViewGroup mContentView = (ViewGroup) this.findViewById(Window.ID_ANDROID_CONTENT);  
     
   //首先使 ChildView 不预留空间  
   View mChildView = mContentView.getChildAt(0);  
   if (mChildView != null) {  
   }  
   int statusBarHeight = 10;  
   //需要设置这个 flag 才能设置状态栏  
   window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);  
   //避免多次调用该方法时,多次移除了 View  
   if (mChildView != null && mChildView.getLayoutParams() != null && mChildView.getLayoutParams().height == statusBarHeight) {  
       //移除假的 View.  
       mContentView.removeView(mChildView);  
       mChildView = mContentView.getChildAt(0);  
   }  
   if (mChildView != null) {  
       FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams();  
       //清除 ChildView 的 marginTop 属性  
       if (lp != null && lp.topMargin >= statusBarHeight) {  
           lp.topMargin -= statusBarHeight;  
           mChildView.setLayoutParams(lp);  
       }  

   }

直接把状态栏的去掉

发布了20 篇原创文章 · 获赞 2 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_28335347/article/details/62045964