Java Code Examples for android.view.View#setFitsSystemWindows()

The following examples show how to use android.view.View#setFitsSystemWindows() . 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: ImmersionBar.java    From ImmersionBar with Apache License 2.0 6 votes vote down vote up
private static void setFitsSystemWindows(View view, boolean applySystemFits) {
    if (view == null) {
        return;
    }
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        if (viewGroup instanceof DrawerLayout) {
            setFitsSystemWindows(viewGroup.getChildAt(0), applySystemFits);
        } else {
            viewGroup.setFitsSystemWindows(applySystemFits);
            viewGroup.setClipToPadding(true);
        }
    } else {
        view.setFitsSystemWindows(applySystemFits);
    }
}
 
Example 2
Source File: MainActivity.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
private void handleTranslucent() {
    Window window = getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.setNavigationBarColor(Color.WHITE);
    } else {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup parent = (ViewGroup) findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 3
Source File: ImmersionBar.java    From MNImageBrowser with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 解决顶部与布局重叠问题
 * Sets fits system windows.
 *
 * @param activity the activity
 */
public static void setFitsSystemWindows(Activity activity) {
    if (activity == null) {
        return;
    }
    ViewGroup parent = activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            if (childView instanceof DrawerLayout) {
                continue;
            }
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 4
Source File: PhotoActivity.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
/**
 * 处理状态栏透明
 */
private void handleStatusbarTransparent() {
    final Window window = getWindow();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.setStatusBarColor(Color.TRANSPARENT);
    } else {
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup content = findViewById(android.R.id.content);
    for (int i = 0, count = content.getChildCount(); i < count; i++) {
        View child = content.getChildAt(i);
        if (child instanceof ViewGroup) {
            child.setFitsSystemWindows(true);
            ((ViewGroup) child).setClipToPadding(false);
        }
    }

    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mPhotoDrawer.getLayoutParams();
    params.topMargin = -DeviceUtil.getStatusBarHeight(this);
    mPhotoDrawer.setLayoutParams(params);
}
 
Example 5
Source File: StatusBarUtil.java    From AndroidPicker with MIT License 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 6
Source File: ImmersionBar.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 解决顶部与布局重叠问题
 * Sets fits system windows.
 *
 * @param activity the activity
 */
public static void setFitsSystemWindows(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 7
Source File: StatusBarUtil.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 8
Source File: StatusBarUtils.java    From MvpRoute with Apache License 2.0 5 votes vote down vote up
/**
 * 设置让内容显示在状态栏之下
 *
 * @param activity
 */
public static void fitWindowAndClipPadding(@NonNull final Activity activity) {
	ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
	for (int i = 0, count = parent.getChildCount(); i < count; i++) {
		View childView = parent.getChildAt(i);
		if (childView instanceof ViewGroup) {
			childView.setFitsSystemWindows(true);
			((ViewGroup) childView).setClipToPadding(true);
		}
	}
}
 
Example 9
Source File: ImmersiveModeUtil.java    From AndroidUiKit with Apache License 2.0 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 10
Source File: StatusBarUtil.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 11
Source File: StatusBarUtil.java    From StatusBarManager with Apache License 2.0 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 12
Source File: StatusBarUtil.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 13
Source File: MainActivity.java    From googlecalendar with Apache License 2.0 5 votes vote down vote up
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(false);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 14
Source File: StatusBarUtil.java    From stynico with MIT License 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 15
Source File: BitToolbarActivity.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 初始化toolbar
 */
private void initToolbar() {

    // 获取 DecorView
    ViewGroup decorView = (ViewGroup) getWindow().getDecorView();

    // 获取到 TitleView
    ViewGroup viewGroup = (ViewGroup) decorView.getChildAt(0);

    if (viewGroup instanceof LinearLayout) {
        View toolbar = LayoutInflater.from(this).inflate(BitManager.getInstance().getToolbarLayout(), null, false);

        viewGroup.addView(toolbar, 0);

        this.mToolbar = toolbar.findViewById(R.id.toolbar);

        setSupportActionBar(this.mToolbar);

        if (getSupportActionBar() != null) {
            //隐藏标题
            getSupportActionBar().setDisplayShowTitleEnabled(false);
            //显示回退按钮
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        ViewGroup contentFrameLayout = findViewById(Window.ID_ANDROID_CONTENT);
        View parentView = contentFrameLayout.getChildAt(0);
        if (parentView != null) {
            parentView.setFitsSystemWindows(true);
        }
    }

}
 
Example 16
Source File: StatusBarUtil.java    From MNProgressHUD with Apache License 2.0 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 17
Source File: StatusBarUtil.java    From VRPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 18
Source File: DialogStack.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
public static void bindDialogToExpandedScreen(Dialog dialog, View rootView, ExpandedScreen expandedScreen) {
	ViewGroup decorView = (ViewGroup) dialog.getWindow().getDecorView();
	decorView.getChildAt(0).setFitsSystemWindows(false);
	// Fix resizing dialogs when status bar in gallery becomes hidden with expanded screen enabled
	if (expandedScreen.isFullScreenLayoutEnabled()) {
		expandedScreen.addAdditionalView(rootView, false);
		decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
				View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
		dialog.setOnDismissListener(d -> expandedScreen.removeAdditionalView(rootView));
		expandedScreen.updatePaddings();
	} else {
		rootView.setFitsSystemWindows(true);
	}
}
 
Example 19
Source File: MainActivity.java    From lbry-android with MIT License 4 votes vote down vote up
public void unsetFitsSystemWindows(View view) {
    view.setFitsSystemWindows(false);
}
 
Example 20
Source File: ModSDK21.java    From SwipeBack with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(21)
public static void afterOnPostCreateSDK21(XC_MethodHook.MethodHookParam mhparams) throws Throwable {
	Class<?> internalStyleable = findClass("com.android.internal.R.styleable", null);
	int[] internalTheme = $(getStaticObjectField(internalStyleable, "Theme"));
	int internalColorPrimary = getStaticIntField(internalStyleable, "Theme_colorPrimaryDark");
	
	SwipeBackActivityHelper helper = $(getAdditionalInstanceField(mhparams.thisObject, "helper"));
	if (helper != null) {
		final Activity activity = $(mhparams.thisObject);

		String packageName = activity.getApplicationInfo().packageName;
		String className = activity.getClass().getName();
		
		mSettings.reload();
		if (!mSettings.getBoolean(packageName, className, Settings.LOLLIPOP_HACK, false))
			return;
		
		ViewGroup root = $(helper.getSwipeBackLayout().getChildAt(0));
		View content = root.getChildAt(0);
		final WindowInsetsColorDrawable bkg = new WindowInsetsColorDrawable(content.getBackground());
		content.setBackground(bkg);
		
		TypedArray a = activity.getTheme().obtainStyledAttributes(internalTheme);
		int primary = a.getColor(internalColorPrimary, 0);
		a.recycle();

		if (primary != 0) {
			bkg.setTopDrawable(new ColorDrawable(primary));
		} else {
			content.setSystemUiVisibility(content.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
			content.setFitsSystemWindows(true);
		}

		root.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
			@Override
			public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
				bkg.setTopInset(insets.getSystemWindowInsetTop());
				activity.getWindow().setStatusBarColor(0);
				return insets;
			}
		});
	}
}