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);  
       }  

   }

直接把狀態欄的去掉

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章