本文整理匯總了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;
}