本文整理汇总了Java中android.support.v4.view.ViewCompat.requestApplyInsets方法的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.requestApplyInsets方法的具体用法?Java ViewCompat.requestApplyInsets怎么用?Java ViewCompat.requestApplyInsets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewCompat
的用法示例。
在下文中一共展示了ViewCompat.requestApplyInsets方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setStatusBarColor
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
static void setStatusBarColor(Activity activity, int statusColor) {
Window window = activity.getWindow();
//取消状态栏透明
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//添加Flag把状态栏设为可绘制模式
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//设置状态栏颜色
window.setStatusBarColor(statusColor);
//设置系统状态栏处于可见状态
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);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: onAttachedToWindow
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
resetTouchBehaviors(false);
if (mNeedsPreDrawListener) {
if (mOnPreDrawListener == null) {
mOnPreDrawListener = new OnPreDrawListener();
}
final ViewTreeObserver vto = getViewTreeObserver();
vto.addOnPreDrawListener(mOnPreDrawListener);
}
if (mLastInsets == null && ViewCompat.getFitsSystemWindows(this)) {
// We're set to fitSystemWindows but we haven't had any insets yet...
// We should request a new dispatch of window insets
ViewCompat.requestApplyInsets(this);
}
mIsAttachedToWindow = true;
}
示例5: 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);
}
}
示例6: 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);
}
示例7: setTransparent
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static void setTransparent(Activity activity, View needOffsetView) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
if (contentView.getChildAt(0) == null) {
return;
}
else if (contentView.getChildCount() > 1 && contentView.getChildAt(1) instanceof StatusBarView) {
contentView.removeViewAt(1);
}
if (contentView.getChildAt(0) instanceof DrawerLayout) {
// 让DrawerLayout中的布局内容可以延伸到状态栏
// 为了实现上述效果,设置DrawerLayout以及两个子View的fitsSystemWindows为false
// 这个带来了一个问题:
// DrawerLayout的内容布局会从屏幕最上方开始绘制,
// 所以需要下移避免被状态栏遮挡的布局,手动设置marginTop。
DrawerLayout drawerLayout = (DrawerLayout) contentView.getChildAt(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
ViewGroup drawerLayoutContent = (ViewGroup) drawerLayout.getChildAt(0);
//如果DrawerLayout的内容布局第一个子View是我们自己的StatusBarView就将它reomve。
if (drawerLayoutContent.getChildAt(0) instanceof StatusBarView) {
drawerLayoutContent.removeViewAt(0);
}
View drawerLayoutContentReal = drawerLayoutContent.getChildAt(0);
// 内容布局不是 LinearLayout 时,清除多余的StatusBarHeight。
if (!(drawerLayoutContent instanceof LinearLayout) &&
drawerLayoutContentReal != null &&
drawerLayoutContentReal.getTag(R.id.tag_top) != null &&
drawerLayoutContentReal.getTag(R.id.tag_top).equals(TAG_ADD_TOP)) {
drawerLayoutContentReal.setPadding(
drawerLayoutContentReal.getPaddingLeft(),
drawerLayoutContentReal.getPaddingTop() - getStatusBarHeight(activity),
drawerLayoutContentReal.getPaddingRight(),
drawerLayoutContentReal.getPaddingBottom()
);
drawerLayoutContentReal.setTag(R.id.tag_top, TAG_REMOVE_TOP);
}
// 设置属性
setDrawerLayoutProperty(drawerLayout, drawerLayoutContent);
} else if (contentView.getChildAt(0) instanceof CoordinatorLayout) {
transparentStatusBar(activity);
setRootViewPaddingTop(activity, PaddingTop.removePaddingTop);
} else {
transparentStatusBar(activity);
ViewCompat.setFitsSystemWindows(contentView.getChildAt(0), false);
ViewCompat.requestApplyInsets(contentView.getChildAt(0));
}
if (needOffsetView != null && needOffsetView.getTag(R.id.tag_need_offset) == null) {
ViewGroup.MarginLayoutParams layoutParams =
(ViewGroup.MarginLayoutParams) needOffsetView.getLayoutParams();
layoutParams.setMargins(
layoutParams.leftMargin,
layoutParams.topMargin + getStatusBarHeight(activity),
layoutParams.rightMargin,
layoutParams.bottomMargin);
needOffsetView.setTag(R.id.tag_need_offset, TAG_NEED_OFFNET);
}
}
示例8: onAttachedToWindow
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mOnAttachStateChangeListener != null) {
mOnAttachStateChangeListener.onViewAttachedToWindow(this);
}
ViewCompat.requestApplyInsets(this);
}
示例9: 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);
}
}
}
}
示例10: setHasEmbeddedTabs
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
boolean isInTabMode;
boolean z;
boolean z2 = true;
this.mHasEmbeddedTabs = hasEmbeddedTabs;
if (this.mHasEmbeddedTabs) {
this.mContainerView.setTabContainer(null);
this.mDecorToolbar.setEmbeddedTabView(this.mTabScrollView);
} else {
this.mDecorToolbar.setEmbeddedTabView(null);
this.mContainerView.setTabContainer(this.mTabScrollView);
}
if (getNavigationMode() == 2) {
isInTabMode = true;
} else {
isInTabMode = false;
}
if (this.mTabScrollView != null) {
if (isInTabMode) {
this.mTabScrollView.setVisibility(0);
if (this.mOverlayLayout != null) {
ViewCompat.requestApplyInsets(this.mOverlayLayout);
}
} else {
this.mTabScrollView.setVisibility(8);
}
}
DecorToolbar decorToolbar = this.mDecorToolbar;
if (this.mHasEmbeddedTabs || !isInTabMode) {
z = false;
} else {
z = true;
}
decorToolbar.setCollapsible(z);
ActionBarOverlayLayout actionBarOverlayLayout = this.mOverlayLayout;
if (this.mHasEmbeddedTabs || !isInTabMode) {
z2 = false;
}
actionBarOverlayLayout.setHasNonEmbeddedTabs(z2);
}
示例11: onAttachedToWindow
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
protected void onAttachedToWindow() {
super.onAttachedToWindow();
ViewParent parent = getParent();
if (parent instanceof AppBarLayout) {
if (this.mOnOffsetChangedListener == null) {
this.mOnOffsetChangedListener = new OffsetUpdateListener();
}
((AppBarLayout) parent).addOnOffsetChangedListener(this.mOnOffsetChangedListener);
}
ViewCompat.requestApplyInsets(this);
}
示例12: doShow
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public void doShow(boolean fromSystem) {
if (this.mCurrentShowAnim != null) {
this.mCurrentShowAnim.cancel();
}
this.mContainerView.setVisibility(0);
if (this.mCurWindowVisibility == 0 && ALLOW_SHOW_HIDE_ANIMATIONS && (this.mShowHideAnimationEnabled || fromSystem)) {
ViewCompat.setTranslationY(this.mContainerView, 0.0f);
float startingY = (float) (-this.mContainerView.getHeight());
if (fromSystem) {
int[] topLeft = new int[]{0, 0};
this.mContainerView.getLocationInWindow(topLeft);
startingY -= (float) topLeft[1];
}
ViewCompat.setTranslationY(this.mContainerView, startingY);
ViewPropertyAnimatorCompatSet anim = new ViewPropertyAnimatorCompatSet();
ViewPropertyAnimatorCompat a = ViewCompat.animate(this.mContainerView).translationY(0.0f);
a.setUpdateListener(this.mUpdateListener);
anim.play(a);
if (this.mContentAnimations && this.mContentView != null) {
ViewCompat.setTranslationY(this.mContentView, startingY);
anim.play(ViewCompat.animate(this.mContentView).translationY(0.0f));
}
anim.setInterpolator(sShowInterpolator);
anim.setDuration(250);
anim.setListener(this.mShowListener);
this.mCurrentShowAnim = anim;
anim.start();
} else {
ViewCompat.setAlpha(this.mContainerView, 1.0f);
ViewCompat.setTranslationY(this.mContainerView, 0.0f);
if (this.mContentAnimations && this.mContentView != null) {
ViewCompat.setTranslationY(this.mContentView, 0.0f);
}
this.mShowListener.onAnimationEnd(null);
}
if (this.mOverlayLayout != null) {
ViewCompat.requestApplyInsets(this.mOverlayLayout);
}
}
示例13: onConfigurationChanged
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
protected void onConfigurationChanged(Configuration newConfig) {
if (VERSION.SDK_INT >= 8) {
super.onConfigurationChanged(newConfig);
}
init(getContext());
ViewCompat.requestApplyInsets(this);
}
示例14: onWindowSystemUiVisibilityChanged
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public void onWindowSystemUiVisibilityChanged(int visible) {
boolean barVisible;
boolean stable;
boolean z = true;
if (VERSION.SDK_INT >= 16) {
super.onWindowSystemUiVisibilityChanged(visible);
}
pullChildren();
int diff = this.mLastSystemUiVisibility ^ visible;
this.mLastSystemUiVisibility = visible;
if ((visible & 4) == 0) {
barVisible = true;
} else {
barVisible = false;
}
if ((visible & 256) != 0) {
stable = true;
} else {
stable = false;
}
if (this.mActionBarVisibilityCallback != null) {
ActionBarVisibilityCallback actionBarVisibilityCallback = this.mActionBarVisibilityCallback;
if (stable) {
z = false;
}
actionBarVisibilityCallback.enableContentAnimations(z);
if (barVisible || !stable) {
this.mActionBarVisibilityCallback.showForSystem();
} else {
this.mActionBarVisibilityCallback.hideForSystem();
}
}
if ((diff & 256) != 0 && this.mActionBarVisibilityCallback != null) {
ViewCompat.requestApplyInsets(this);
}
}
示例15: onAttachedToWindow
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public void onAttachedToWindow() {
super.onAttachedToWindow();
resetTouchBehaviors();
if (this.mNeedsPreDrawListener) {
if (this.mOnPreDrawListener == null) {
this.mOnPreDrawListener = new OnPreDrawListener();
}
getViewTreeObserver().addOnPreDrawListener(this.mOnPreDrawListener);
}
if (this.mLastInsets == null && ViewCompat.getFitsSystemWindows(this)) {
ViewCompat.requestApplyInsets(this);
}
this.mIsAttachedToWindow = true;
}