移动开发---渐变状态栏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhanwei0102/article/details/80424184
private View statusBarView;
@Override
protected void onCreate(Bundle savedInstanceState) {
 
   Looper.myQueue().addIdleHandler( new MessageQueue.IdleHandler() {
     @Override
     public boolean queueIdle() {
       if (isStatusBar()) {
         initStatusBar();
         getWindow().getDecorView().addOnLayoutChangeListener( new View.OnLayoutChangeListener() {
           @Override
           public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
             initStatusBar();
           }
         });
       }
     
       return false ;
     }
   });
}
private void initStatusBar() {
   if (statusBarView == null ) {
     int identifier = getResources().getIdentifier( "statusBarBackground" , "id" , "android" );
     statusBarView = getWindow().findViewById(identifier);
   }
   if (statusBarView != null ) {
       statusBarView.setBackgroundResource( "你的渐变drawable资源id" );
   }
}
 
  protected boolean isStatusBar() {
   return true ;
}

猜你喜欢

转载自blog.csdn.net/zhanwei0102/article/details/80424184