Android View Activity内部顶部通知实现方式收录

Android View Activity内部顶部通知实现方式收录_第1张图片Android View Activity内部顶部通知实现方式收录_第2张图片


public void show() {
        if (cookieView != null) {
            final ViewGroup decorView = (ViewGroup) context.getWindow().getDecorView();
            final ViewGroup content = (ViewGroup) decorView.findViewById(android.R.id.content);
            if (cookieView.getParent() == null) {
                if (cookieView.getLayoutGravity() == Gravity.BOTTOM) {
                    content.addView(cookieView);
                } else {
                    decorView.addView(cookieView);
                }
            }
        }
    }

private final class DecorView extends FrameLayout implements RootViewSurfaceTaker {


decorView 是一个帧布局,最后调用的addView所添加的View对象,自然而然显示在decorView中的最上层


实现来源 https://github.com/liuguangqiang/CookieBar



你可能感兴趣的:(Android,UI,View)