android.view.ViewGroup#getPaddingTop ( )源码实例Demo

下面列出了android.view.ViewGroup#getPaddingTop ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ClassifyView   文件: PrimitiveSimpleAdapter.java
public ViewHolder(View itemView) {
    super(itemView);
    if (itemView instanceof CanMergeView) {
        mCanMergeView = (CanMergeView) itemView;
    } else if (itemView instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) itemView;
        paddingLeft = group.getPaddingLeft();
        paddingRight = group.getPaddingRight();
        paddingTop = group.getPaddingTop();
        paddingBottom = group.getPaddingBottom();
        //只遍历一层 寻找第一个符合条件的view
        for (int i = 0; i < group.getChildCount(); i++) {
            View child = group.getChildAt(i);
            if (child instanceof CanMergeView) {
                mCanMergeView = (CanMergeView) child;
                break;
            }
        }
    }
}
 
源代码2 项目: FreeRadioGroup   文件: FreeRadioGroup.java
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    if (moveable) {
        ViewGroup parentView = ((ViewGroup) getParent());
        MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
        viewWidth = getRight() - getLeft();
        viewHight = getBottom() - getTop();
        parentWidth = parentView.getMeasuredWidth();
        parentHeight = parentView.getMeasuredHeight();
        minLeftMargin = lp.leftMargin;
        leftPadding = parentView.getPaddingLeft();
        rightDistance = lp.rightMargin + parentView.getPaddingRight();
        maxLeftMargin = parentWidth - rightDistance - viewWidth - leftPadding;
        minTopMargin = lp.topMargin;
        topPadding = parentView.getPaddingTop();
        bottomDistance = lp.bottomMargin + parentView.getPaddingBottom();
        maxTopMargin = parentHeight - bottomDistance - viewHight - topPadding;
    }
}
 
源代码3 项目: ProjectX   文件: CenterLinearLayoutManager.java
@Override
public void layoutDecorated(@NonNull View child, int left, int top, int right, int bottom) {
    if (!mCenter) {
        super.layoutDecorated(child, left, top, right, bottom);
        return;
    }
    final int leftDecorationWidth = getLeftDecorationWidth(child);
    final int topDecorationHeight = getTopDecorationHeight(child);
    final int rightDecorationWidth = getRightDecorationWidth(child);
    final int bottomDecorationHeight = getBottomDecorationHeight(child);
    final ViewGroup parent = (ViewGroup) child.getParent();
    final int offset;
    if (getOrientation() == HORIZONTAL) {
        final int contentHeight = parent.getMeasuredHeight() -
                parent.getPaddingTop() - parent.getPaddingBottom();
        offset = (contentHeight - (bottom - top)) / 2;
        child.layout(left + leftDecorationWidth, top + topDecorationHeight + offset,
                right - rightDecorationWidth, bottom - bottomDecorationHeight + offset);
    } else {
        final int contentWidth = parent.getMeasuredWidth() -
                parent.getPaddingLeft() - parent.getPaddingRight();
        offset = (contentWidth - (right - left)) / 2;
        child.layout(left + leftDecorationWidth + offset, top + topDecorationHeight,
                right - rightDecorationWidth + offset, bottom - bottomDecorationHeight);
    }
}
 
源代码4 项目: Focus   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码5 项目: tysq-android   文件: StatusBarUtils.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码6 项目: Focus   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码7 项目: styT   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
private static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                         @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码8 项目: MaoWanAndoidClient   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码9 项目: android-openslmediaplayer   文件: MainActivity.java
private void onDecorViewInitialized() {
    // measure status bar & navigation bar height
    final ViewGroup contents = (ViewGroup) findViewById(R.id.activity_contents);
    final int statusBarOffset = contents.getPaddingTop();
    final int navBarOffset = contents.getPaddingBottom();

    // apply to navigation drawer
    mNavigationDrawerFragment.setSystemBarsOffset(statusBarOffset, navBarOffset);
}
 
源代码10 项目: stynico   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
@Override
public void run() {
    coordinatorLayout.requestLayout();
}
   });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码11 项目: browser   文件: OverflowAdapter.java
/**
 * 调整位置Padding
 * @param parent
 * @param background
 */
private void setViewPadding(ViewGroup parent, int background) {
    int[] rect = new int[4];
    rect[0] = parent.getPaddingLeft();
    rect[1] = parent.getPaddingTop();
    rect[2] = parent.getPaddingRight();
    rect[3] = parent.getPaddingBottom();
    parent.setBackgroundResource(background);
    parent.setPadding(rect[0], rect[1], rect[2], rect[3]);
}
 
源代码12 项目: FastAndroid   文件: UIStatusBarController.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码13 项目: VRPlayer   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
    @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码14 项目: ProjectX   文件: CenterLinearLayoutManager.java
@Override
public void layoutDecoratedWithMargins(@NonNull View child, int left, int top, int right, int bottom) {
    if (!mCenter) {
        super.layoutDecoratedWithMargins(child, left, top, right, bottom);
        return;
    }
    final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
    final int leftDecorationWidth = getLeftDecorationWidth(child);
    final int topDecorationHeight = getTopDecorationHeight(child);
    final int rightDecorationWidth = getRightDecorationWidth(child);
    final int bottomDecorationHeight = getBottomDecorationHeight(child);
    final ViewGroup parent = (ViewGroup) child.getParent();
    final int offset;
    if (getOrientation() == RecyclerView.HORIZONTAL) {
        final int contentHeight = parent.getMeasuredHeight() -
                parent.getPaddingTop() - parent.getPaddingBottom();
        offset = (contentHeight - (bottom - top)) / 2;
        child.layout(left + leftDecorationWidth + lp.leftMargin,
                top + topDecorationHeight + lp.topMargin + offset,
                right - rightDecorationWidth - lp.rightMargin,
                bottom - bottomDecorationHeight - lp.bottomMargin + offset);
    } else {
        final int contentWidth = parent.getMeasuredWidth() -
                parent.getPaddingLeft() - parent.getPaddingRight();
        offset = (contentWidth - (right - left)) / 2;
        child.layout(left + leftDecorationWidth + offset + lp.leftMargin,
                top + topDecorationHeight + lp.topMargin,
                right - rightDecorationWidth - lp.rightMargin + offset,
                bottom - bottomDecorationHeight - lp.bottomMargin);
    }
}
 
源代码15 项目: NCalendar   文件: GridCalendarAdapter.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View calendarItemView = viewList.get(position);
    int realHeight = parent.getMeasuredHeight() - parent.getPaddingBottom() - parent.getPaddingTop();
    AbsListView.LayoutParams params = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, realHeight / (viewList.size() / 7));
    calendarItemView.setLayoutParams(params);
    ((CalendarView2) parent).bindView(position, calendarItemView);
    return calendarItemView;
}
 
源代码16 项目: LRecyclerView   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
源代码17 项目: talk-android   文件: MDRootLayout.java
private void invalidateDividersForScrollingView(ViewGroup view, final boolean setForTop, boolean setForBottom, boolean hasButtons) {
    if (setForTop && view.getChildCount() > 0) {
        mDrawTopDivider = mTitleBar != null &&
                mTitleBar.getVisibility() != View.GONE &&
                //Not scrolled to the top.
                view.getScrollY() + view.getPaddingTop() > view.getChildAt(0).getTop();

    }
    if (setForBottom && view.getChildCount() > 0) {
        mDrawBottomDivider = hasButtons &&
                view.getScrollY() + view.getHeight() - view.getPaddingBottom() < view.getChildAt(view.getChildCount() - 1).getBottom();
    }
}
 
源代码18 项目: AndroidProjects   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
public static void setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
        View rootView = contentView.getChildAt(0);
        int statusBarHeight = getStatusBarHeight(activity);
        if (rootView != null && rootView instanceof CoordinatorLayout) {
            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                coordinatorLayout.setFitsSystemWindows(false);
                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
                if (isNeedRequestLayout) {
                    contentView.setPadding(0, statusBarHeight, 0, 0);
                    coordinatorLayout.post(new Runnable() {
                        @Override
                        public void run() {
                            coordinatorLayout.requestLayout();
                        }
                    });
                }
            } else {
                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
            }
        } else {
            contentView.setPadding(0, statusBarHeight, 0, 0);
            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
        }
        setTransparentForWindow(activity);
    }
}
 
public BaseHolder(LayoutInflater inflater, ViewGroup parent, @LayoutRes int layoutId, boolean isFillParent) {
  super(inflate(inflater, parent, layoutId));
  if (isFillParent && parent != null) {
    getItemView().getLayoutParams().height = parent.getMeasuredHeight() - (parent.getPaddingTop() + parent.getPaddingBottom());
  }
}
 
源代码20 项目: NewFastFrame   文件: StatusBarUtil.java
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @param activity       需要设置的activity
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */

public static void setColorForSwipeBack(Activity activity, @ColorInt int color,

                                        @IntRange(from = 0, to = 255) int statusBarAlpha) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {


        ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));

        View rootView = contentView.getChildAt(0);

        int statusBarHeight = getStatusBarHeight(activity);

        if (rootView != null && rootView instanceof CoordinatorLayout) {

            final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;

            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

                coordinatorLayout.setFitsSystemWindows(false);

                contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));

                boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;

                if (isNeedRequestLayout) {

                    contentView.setPadding(0, statusBarHeight, 0, 0);

                    coordinatorLayout.post(new Runnable() {

                        @Override

                        public void run() {

                            coordinatorLayout.requestLayout();

                        }

                    });

                }

            } else {

                coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));

            }

        } else {

            contentView.setPadding(0, statusBarHeight, 0, 0);

            contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));

        }

        setTransparentForWindow(activity);

    }

}
 
 方法所在类