Java Code Examples for android.view.ViewGroup#getPaddingTop()

The following examples show how to use android.view.ViewGroup#getPaddingTop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CenterLinearLayoutManager.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 2
Source File: FreeRadioGroup.java    From FreeRadioGroup with Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example 3
Source File: PrimitiveSimpleAdapter.java    From ClassifyView with Apache License 2.0 6 votes vote down vote up
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;
            }
        }
    }
}
 
Example 4
Source File: StatusBarUtil.java    From VRPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 5
Source File: StatusBarUtil.java    From AndroidProjects with MIT License 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 6
Source File: MDRootLayout.java    From talk-android with MIT License 5 votes vote down vote up
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();
    }
}
 
Example 7
Source File: StatusBarUtil.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 8
Source File: GridCalendarAdapter.java    From NCalendar with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: CenterLinearLayoutManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 10
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 11
Source File: UIStatusBarController.java    From FastAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 12
Source File: OverflowAdapter.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 调整位置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]);
}
 
Example 13
Source File: StatusBarUtil.java    From stynico with MIT License 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 14
Source File: MainActivity.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: StatusBarUtil.java    From MaoWanAndoidClient with Apache License 2.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 16
Source File: StatusBarUtil.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 17
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 18
Source File: StatusBarUtils.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);
    }
}
 
Example 19
Source File: BaseHolder.java    From recyclerview-multistate-section-endless-adapter with Apache License 2.0 4 votes vote down vote up
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());
  }
}
 
Example 20
Source File: StatusBarUtil.java    From NewFastFrame with Apache License 2.0 2 votes vote down vote up
/**
 * 为滑动返回界面设置状态栏颜色
 *
 * @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);

    }

}