本文整理汇总了Java中android.support.v4.view.ViewCompat.setFitsSystemWindows方法的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.setFitsSystemWindows方法的具体用法?Java ViewCompat.setFitsSystemWindows怎么用?Java ViewCompat.setFitsSystemWindows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewCompat
的用法示例。
在下文中一共展示了ViewCompat.setFitsSystemWindows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: i
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void i() {
// Add a dummy view that will receive inner touch events.
View dummyView = new View(getContext());
DummyBehavior dummyBehavior = new DummyBehavior();
// I *think* this is needed for dummyView to be identified as "topmost" and receive events
// before any other view.
ViewCompat.setElevation(dummyView, ViewCompat.getElevation(this));
// Make sure it does not fit windows, or it will consume insets before the AppBarLayout.
ViewCompat.setFitsSystemWindows(dummyView, false);
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
params.setBehavior(dummyBehavior);
addView(dummyView, params);
// Wait to get our own behavior.
getViewTreeObserver().addOnGlobalLayoutListener(this);
}
示例2: translucentStatusBar
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {
Window window = activity.getWindow();
//添加Flag把状态栏设为可绘制模式
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
if (hideStatusBarBackground) {
//如果为全透明模式,取消设置Window半透明的Flag
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//设置状态栏为透明
window.setStatusBarColor(Color.TRANSPARENT);
//设置window的状态栏不可见
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
} else {
//如果为半透明模式,添加设置Window半透明的Flag
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//设置系统状态栏处于可见状态
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
//view不根据系统窗口来调整自己的布局
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mChildView = mContentView.getChildAt(0);
if (mChildView != null) {
ViewCompat.setFitsSystemWindows(mChildView, false);
ViewCompat.requestApplyInsets(mChildView);
}
}
示例3: setStatusBarColor
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* set StatusBarColor
*/
public static void setStatusBarColor(Activity activity, int statusColor) {
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(statusColor);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mChildView = mContentView.getChildAt(0);
if (mChildView != null) {
ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
return insets;
}
});
ViewCompat.setFitsSystemWindows(mChildView, true);
ViewCompat.requestApplyInsets(mChildView);
}
}
示例4: onMeasureChild
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public boolean onMeasureChild(CoordinatorLayout parent, View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
int childLpHeight = child.getLayoutParams().height;
if (childLpHeight == -1 || childLpHeight == -2) {
View header = findFirstDependency(parent.getDependencies(child));
if (header != null) {
if (ViewCompat.getFitsSystemWindows(header) && !ViewCompat.getFitsSystemWindows(child)) {
ViewCompat.setFitsSystemWindows(child, true);
if (ViewCompat.getFitsSystemWindows(child)) {
child.requestLayout();
return true;
}
}
if (ViewCompat.isLaidOut(header)) {
int availableHeight = MeasureSpec.getSize(parentHeightMeasureSpec);
if (availableHeight == 0) {
availableHeight = parent.getHeight();
}
parent.onMeasureChild(child, parentWidthMeasureSpec, widthUsed, MeasureSpec.makeMeasureSpec((availableHeight - header.getMeasuredHeight()) + getScrollRange(header), childLpHeight == -1 ? 1073741824 : Integer.MIN_VALUE), heightUsed);
return true;
}
}
}
return false;
}
示例5: forceFitsSystemWindows
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* 强制rootView下面的子View的FitsSystemWindows为false
*/
public static void forceFitsSystemWindows(ViewGroup viewGroup) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int count = viewGroup.getChildCount();
for (int i = 0; i < count; i++) {
View view = viewGroup.getChildAt(i);
if (view instanceof ViewGroup) {
forceFitsSystemWindows((ViewGroup) view);
} else {
if (ViewCompat.getFitsSystemWindows(view)) {
ViewCompat.setFitsSystemWindows(view, false);
}
}
}
}
}
示例6: onAttachedToWindow
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
// Add an OnOffsetChangedListener if possible
final ViewParent parent = getParent();
if (parent instanceof AppBarLayout) {
// Copy over from the ABL whether we should fit system windows
ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));
if (mOnOffsetChangedListener == null) {
mOnOffsetChangedListener = new OffsetUpdateListener();
}
((AppBarLayout) parent).addOnOffsetChangedListener(mOnOffsetChangedListener);
// We're attached, so lets request an inset dispatch
ViewCompat.requestApplyInsets(this);
}
}
示例7: onLayoutChild
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
// First let the parent lay it out
if (mState != STATE_DRAGGING && mState != STATE_SETTLING) {
if (ViewCompat.getFitsSystemWindows(parent) &&
!ViewCompat.getFitsSystemWindows(child)) {
ViewCompat.setFitsSystemWindows(child, true);
}
parent.onLayoutChild(child, layoutDirection);
}
// Offset the bottom sheet
mParentHeight = parent.getHeight();
mMinOffset = Math.max(0, mParentHeight - child.getHeight());
mMaxOffset = Math.max(mParentHeight - mPeekHeight, mMinOffset);
/**
* New behavior
*/
if (mState == STATE_ANCHOR_POINT) {
ViewCompat.offsetTopAndBottom(child, mAnchorPoint);
} else if (mState == STATE_EXPANDED) {
ViewCompat.offsetTopAndBottom(child, mMinOffset);
} else if (mHideable && mState == STATE_HIDDEN) {
ViewCompat.offsetTopAndBottom(child, mParentHeight);
} else if (mState == STATE_COLLAPSED) {
ViewCompat.offsetTopAndBottom(child, mMaxOffset);
}
if (mViewDragHelper == null) {
mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
}
mViewRef = new WeakReference<>(child);
mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
return true;
}
示例8: setStatusBarLightMode
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static void setStatusBarLightMode(Activity activity, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//判断是否为小米或魅族手机,如果是则将状态栏文字改为黑色
if (MIUISetStatusBarLightMode(activity, true) || FlymeSetStatusBarLightMode(activity, true)) {
//设置状态栏为指定颜色
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0
activity.getWindow().setStatusBarColor(color);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4
//调用修改状态栏颜色的方法
setStatusBarColor(activity, color);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//如果是6.0以上将状态栏文字改为黑色,并设置状态栏颜色
activity.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
activity.getWindow().setStatusBarColor(color);
//fitsSystemWindow 为 false, 不预留系统栏位置.
ViewGroup mContentView = (ViewGroup) activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
View mChildView = mContentView.getChildAt(0);
if (mChildView != null) {
ViewCompat.setFitsSystemWindows(mChildView, true);
ViewCompat.requestApplyInsets(mChildView);
}
}
}
}
示例9: i
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void i() {
helper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
// Add a dummy view that will receive inner touch events.
View dummyView = new View(getContext());
dummyBehavior = new DummyBehavior();
// I *think* this is needed for dummyView to be identified as "topmost" and receive events
// before any other view.
ViewCompat.setElevation(dummyView, ViewCompat.getElevation(this));
// Make sure it does not fit windows, or it will consume insets before the AppBarLayout.
ViewCompat.setFitsSystemWindows(dummyView, false);
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.setBehavior(dummyBehavior);
addView(dummyView, params);
}
示例10: setStatusBarColorForCollapsingToolbar
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* compat for CollapsingToolbarLayout
*/
public static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, CollapsingToolbarLayout collapsingToolbarLayout,
Toolbar toolbar, int statusColor) {
Window window = activity.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
View mChildView = mContentView.getChildAt(0);
if (mChildView != null) {
ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
return insets;
}
});
ViewCompat.setFitsSystemWindows(mChildView, true);
ViewCompat.requestApplyInsets(mChildView);
}
((View) appBarLayout.getParent()).setFitsSystemWindows(true);
appBarLayout.setFitsSystemWindows(true);
collapsingToolbarLayout.setFitsSystemWindows(true);
collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(true);
toolbar.setFitsSystemWindows(false);
collapsingToolbarLayout.setStatusBarScrimColor(statusColor);
}
示例11: onLayoutChild
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
ViewCompat.setFitsSystemWindows(child, true);
}
int savedTop = child.getTop();
// First let the parent lay it out
parent.onLayoutChild(child, layoutDirection);
// Offset the bottom sheet
mParentHeight = parent.getHeight();
int peekHeight;
if (mPeekHeightAuto) {
if (mPeekHeightMin == 0) {
mPeekHeightMin = parent.getResources().getDimensionPixelSize(
R.dimen.design_bottom_sheet_peek_height_min);
}
peekHeight = Math.max(mPeekHeightMin, mParentHeight - parent.getWidth() * 9 / 16);
} else {
peekHeight = mPeekHeight;
}
mMinOffset = Math.max(0, mParentHeight - child.getHeight());
mMaxOffset = Math.max(mParentHeight - peekHeight, mMinOffset);
if (mState == STATE_EXPANDED) {
ViewCompat.offsetTopAndBottom(child, mMinOffset);
} else if (mHideable && mState == STATE_HIDDEN) {
ViewCompat.offsetTopAndBottom(child, mParentHeight);
} else if (mState == STATE_COLLAPSED) {
ViewCompat.offsetTopAndBottom(child, mMaxOffset);
} else if (mState == STATE_DRAGGING || mState == STATE_SETTLING) {
ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop());
}
if (mViewDragHelper == null) {
mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
}
mViewRef = new WeakReference<>(child);
mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
return true;
}
示例12: tintStatusBar
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static void tintStatusBar(Activity activity, @ColorInt int statusBarColor, @FloatRange(from = 0.0, to = 1.0) float alpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
Window window = activity.getWindow();
ViewGroup decorView = (ViewGroup) window.getDecorView();
ViewGroup contentView = (ViewGroup) window.getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
View rootView = contentView.getChildAt(0);
if (rootView != null && !ViewCompat.getFitsSystemWindows(rootView)) {
ViewCompat.setFitsSystemWindows(rootView, true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// window.setStatusBarColor(Color.TRANSPARENT);
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
if (statusBarColor != COLOR_INVALID_VAL) {
window.setStatusBarColor(statusBarColor);
}
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
setStatusBar(decorView, statusBarColor, true);
setTranslucentView(decorView, alpha);
}
}
示例13: onLayoutChild
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) {
if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) {
ViewCompat.setFitsSystemWindows(child, true);
}
int savedTop = child.getTop();
// First let the parent lay it out
parent.onLayoutChild(child, layoutDirection);
// Offset the bottom sheet
mParentHeight = parent.getHeight();
int peekHeight;
if (mPeekHeightAuto) {
if (mPeekHeightMin == 0) {
mPeekHeightMin = parent.getResources().getDimensionPixelSize(
R.dimen.design_bottom_sheet_peek_height_min);
}
peekHeight = Math.max(mPeekHeightMin, mParentHeight - parent.getWidth() * 9 / 16);
} else {
peekHeight = mPeekHeight;
}
mMinOffset = Math.max(0, mParentHeight - child.getHeight());
mMaxOffset = Math.max(mParentHeight - peekHeight, mMinOffset);
if (mState == STATE_EXPANDED) {
ViewCompat.offsetTopAndBottom(child, mMinOffset);
} else if (mHideable && mState == STATE_HIDDEN) {
ViewCompat.offsetTopAndBottom(child, mParentHeight);
} else if (mState == STATE_COLLAPSED) {
ViewCompat.offsetTopAndBottom(child, mMaxOffset);
} else if (mState == STATE_DRAGGING || mState == STATE_SETTLING) {
ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop());
}
if (mViewDragHelper == null) {
mViewDragHelper = ViewDragHelper.create(parent, mDragCallback);
}
mViewRef = new WeakReference<>(child);
mNestedScrollingChildRef = new WeakReference<>(findScrollingChild(child));
return true;
}
示例14: tintStatusBar
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* Android4.4以上的状态栏着色
*
* @param window 一般都是用于Activity的window,也可以是其他的例如Dialog,DialogFragment
* @param statusBarColor 状态栏颜色
* @param alpha 透明栏透明度[0.0-1.0]
*/
public static void tintStatusBar(Window window,
@ColorInt int statusBarColor,
@FloatRange(from = 0.0, to = 1.0) float alpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
ViewGroup decorView = (ViewGroup) window.getDecorView();
ViewGroup contentView = (ViewGroup) window.getDecorView()
.findViewById(Window.ID_ANDROID_CONTENT);
View rootView = contentView.getChildAt(0);
if (rootView != null) {
ViewCompat.setFitsSystemWindows(rootView, true);
}
setStatusBar(decorView, statusBarColor, true);
setTranslucentView(decorView, alpha);
}
示例15: immersiveStatusBar
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* Android4.4以上的沉浸式全屏模式
* 注:
* 1.删除fitsSystemWindows属性:Android5.0以上使用该方法如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性
* 或者调用forceFitsSystemWindows方法
* 2.不删除fitsSystemWindows属性:也可以区别处理,Android5.0以上使用自己的方式实现,不调用该方法
*
* @param window 一般都是用于Activity的window,也可以是其他的例如Dialog,DialogFragment
* @param alpha 透明栏透明度[0.0-1.0]
*/
public static void immersiveStatusBar(Window window,
@FloatRange(from = 0.0, to = 1.0) float alpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
window.getDecorView().setSystemUiVisibility(systemUiVisibility);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
ViewGroup decorView = (ViewGroup) window.getDecorView();
ViewGroup contentView = (ViewGroup) window.getDecorView()
.findViewById(Window.ID_ANDROID_CONTENT);
View rootView = contentView.getChildAt(0);
int statusBarHeight = getStatusBarHeight(window.getContext());
if (rootView != null) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) rootView.getLayoutParams();
ViewCompat.setFitsSystemWindows(rootView, true);
lp.topMargin = -statusBarHeight;
rootView.setLayoutParams(lp);
}
setTranslucentView(decorView, alpha);
}