Android development custom status bar

   Window window = this.getWindow();  
   ViewGroup mContentView = (ViewGroup) this.findViewById(Window.ID_ANDROID_CONTENT);  
     
   // First make ChildView not reserve space  
   View mChildView = mContentView.getChildAt(0);  
   if (mChildView != null) {  
   }  
   int statusBarHeight = 10;  
   // You need to set this flag to set the status bar  
   window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);  
   // Avoid removing the View multiple times when calling this method multiple times  
   if (mChildView != null && mChildView.getLayoutParams() != null && mChildView.getLayoutParams().height == statusBarHeight) {  
       // Remove the fake View.  
       mContentView.removeView(mChildView);  
       mChildView = mContentView.getChildAt(0);  
   }  
   if (mChildView != null) {  
       FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams();  
       // Clear the marginTop property of ChildView  
       if (lp != null && lp.topMargin >= statusBarHeight) {  
           lp.topMargin -= statusBarHeight;  
           mChildView.setLayoutParams (lp);  
       }  

   }

Remove the status bar directly

Published 20 original articles · Likes2 · Visits 10,000+

Guess you like

Origin blog.csdn.net/qq_28335347/article/details/62045964