Snackbar and CollapsingToolbarLayout with TranslucentNavigation

为君一笑 提交于 2019-12-08 07:35:30
    private static void show(final Activity activity, Snackbar snackbar) {
    if (ScreenUtils.isTranslucentNavigationBar(activity)){
        final FrameLayout snackBarView = (FrameLayout) snackbar.getView();
        final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) snackBarView.getChildAt(0).getLayoutParams();
        params.setMargins(params.leftMargin,
                params.topMargin,
                params.rightMargin,
                params.bottomMargin + ScreenUtils.getNavigationBarHeight(activity));

        snackBarView.getChildAt(0).setLayoutParams(params);
    }
    snackbar.show();
}

public static boolean isTranslucentNavigationBar(Activity activity) {
    Window w = activity.getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    int flags = lp.flags;
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && (flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
            == WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;

}

This ideal works for me!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!