本文整理匯總了Java中android.support.v4.widget.DrawerLayout.setFitsSystemWindows方法的典型用法代碼示例。如果您正苦於以下問題:Java DrawerLayout.setFitsSystemWindows方法的具體用法?Java DrawerLayout.setFitsSystemWindows怎麽用?Java DrawerLayout.setFitsSystemWindows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.widget.DrawerLayout
的用法示例。
在下文中一共展示了DrawerLayout.setFitsSystemWindows方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setColorForDrawerLayoutDiff
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 為DrawerLayout 布局設置狀態欄變色(5.0以下無半透明效果,不建議使用)
*
* @param activity 需要設置的activity
* @param drawerLayout DrawerLayout
* @param color 狀態欄顏色值
*/
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 生成一個狀態欄大小的矩形
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
} else {
// 添加 statusBarView 到布局中
StatusBarView statusBarView = createStatusBarView(activity, color);
contentLayout.addView(statusBarView, 0);
}
// 內容布局不是 LinearLayout 時,設置padding top
if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
}
// 設置屬性
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawerLayout.setFitsSystemWindows(false);
contentLayout.setFitsSystemWindows(false);
contentLayout.setClipToPadding(true);
drawer.setFitsSystemWindows(false);
}
}
示例2: setTranslucentForDrawerLayoutDiff
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 為 DrawerLayout 布局設置狀態欄透明(5.0以上半透明效果,不建議使用)
*
* @param activity 需要設置的activity
* @param drawerLayout DrawerLayout
*/
@Deprecated
public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// 設置狀態欄透明
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 設置內容布局屬性
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
contentLayout.setFitsSystemWindows(true);
contentLayout.setClipToPadding(true);
// 設置抽屜布局屬性
ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
vg.setFitsSystemWindows(false);
// 設置 DrawerLayout 屬性
drawerLayout.setFitsSystemWindows(false);
}
}
示例3: setStatusBarAlpha4Drawer
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 為DrawerLayout設置狀態欄透明度
* <p>DrawLayout需設置 {@code android:fitsSystemWindows="true"}</p>
*
* @param activity activity
* @param drawer drawerLayout
* @param fakeStatusBar 偽造狀態欄
* @param alpha 狀態欄透明度
* @param isTop drawerLayout是否在頂層
*/
public static void setStatusBarAlpha4Drawer(@NonNull final Activity activity,
@NonNull final DrawerLayout drawer,
@NonNull final View fakeStatusBar,
@IntRange(from = 0, to = 255) final int alpha,
final boolean isTop) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
drawer.setFitsSystemWindows(false);
transparentStatusBar(activity);
setStatusBarAlpha(fakeStatusBar, isTop ? alpha : 0);
for (int i = 0, len = drawer.getChildCount(); i < len; i++) {
drawer.getChildAt(i).setFitsSystemWindows(false);
}
if (isTop) {
hideAlphaView(activity);
} else {
addStatusBarAlpha(activity, alpha, false);
}
}
示例4: setTransparentForDrawerLayout
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 為 DrawerLayout 布局設置狀態欄透明
*
* @param activity 需要設置的activity
* @param drawerLayout DrawerLayout
*/
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
// 內容布局不是 LinearLayout 時,設置padding top
if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
}
// 設置屬性
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawerLayout.setFitsSystemWindows(false);
contentLayout.setFitsSystemWindows(false);
contentLayout.setClipToPadding(true);
drawer.setFitsSystemWindows(false);
}
示例5: _initDrawerLayout
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 初始化 DrawerLayout
*
* @param drawerLayout DrawerLayout
* @param navView NavigationView
*/
private void _initDrawerLayout(DrawerLayout drawerLayout, NavigationView navView) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
//將側邊欄頂部延伸至status bar
drawerLayout.setFitsSystemWindows(true);
//將主頁麵頂部延伸至status bar
drawerLayout.setClipToPadding(false);
}
drawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
@Override
public void onDrawerClosed(View drawerView) {
mHandler.sendEmptyMessage(mItemId);
}
});
navView.setNavigationItemSelectedListener(this);
}
示例6: setTranslucentForDrawerLayoutDiff
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 為 DrawerLayout 布局設置狀態欄透明(5.0以上半透明效果,不建議使用)
*
* @param activity 需要設置的activity
* @param drawerLayout DrawerLayout
*/
@Deprecated
public static void setTranslucentForDrawerLayoutDiff(Activity activity,
DrawerLayout drawerLayout)
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
// 設置狀態欄透明
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 設置內容布局屬性
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
contentLayout.setFitsSystemWindows(true);
contentLayout.setClipToPadding(true);
// 設置抽屜布局屬性
ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
vg.setFitsSystemWindows(false);
// 設置 DrawerLayout 屬性
drawerLayout.setFitsSystemWindows(false);
}
}
示例7: setColorForDrawerLayoutDiff
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 為DrawerLayout 布局設置狀態欄變色(5.0以下無半透明效果,不建議使用)
*
* @param activity 需要設置的activity
* @param drawerLayout DrawerLayout
* @param color 狀態欄顏色值
*/
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 生成一個狀態欄大小的矩形
View statusBarView = createStatusBarView(activity, color);
// 添加 statusBarView 到布局中
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
contentLayout.addView(statusBarView, 0);
// 內容布局不是 LinearLayout 時,設置padding top
if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
}
// 設置屬性
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawerLayout.setFitsSystemWindows(false);
contentLayout.setFitsSystemWindows(false);
contentLayout.setClipToPadding(true);
drawer.setFitsSystemWindows(false);
}
}
示例8: tintStatusBarForDrawer
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* Android4.4以上的狀態欄著色(針對於DrawerLayout)
* 注:
* 1.如果出現界麵展示不正確,刪除布局中所有fitsSystemWindows屬性,尤其是DrawerLayout的fitsSystemWindows屬性
* 2.可以版本判斷在5.0以上不調用該方法,使用係統自帶
*
* @param activity Activity對象
* @param drawerLayout DrawerLayout對象
* @param statusBarColor 狀態欄顏色
* @param alpha 透明欄透明度[0.0-1.0]
*/
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout,
@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 drawContent = (ViewGroup) drawerLayout.getChildAt(0);
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);
drawerLayout.setStatusBarBackgroundColor(statusBarColor);
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);
}
setStatusBar(decorView, statusBarColor, true, true);
setTranslucentView(decorView, alpha);
drawerLayout.setFitsSystemWindows(false);
drawContent.setFitsSystemWindows(true);
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawer.setFitsSystemWindows(false);
}
示例9: setDrawerLayoutProperty
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 設置 DrawerLayout 屬性
*
* @param drawerLayout DrawerLayout
* @param drawerLayoutContentLayout DrawerLayout 的內容布局
*/
private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawerLayoutContentLayout) {
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawerLayout.setFitsSystemWindows(false);
drawerLayoutContentLayout.setFitsSystemWindows(false);
drawerLayoutContentLayout.setClipToPadding(true);
drawer.setFitsSystemWindows(false);
}
示例10: setTransparentForDrawerLayout
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 為 DrawerLayout 布局設置狀態欄透明
*
* @param activity 需要設置的activity
* @param drawerLayout DrawerLayout
*/
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow()
.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow()
.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
activity.getWindow()
.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
// 內容布局不是 LinearLayout 時,設置padding top
if (!(contentLayout instanceof LinearLayout) &&
contentLayout.getChildAt(1) != null) {
contentLayout.getChildAt(1)
.setPadding(0, getStatusBarHeight(activity), 0, 0);
}
// 設置屬性
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawerLayout.setFitsSystemWindows(false);
contentLayout.setFitsSystemWindows(false);
contentLayout.setClipToPadding(true);
drawer.setFitsSystemWindows(false);
}
示例11: setColorForDrawerLayout
import android.support.v4.widget.DrawerLayout; //導入方法依賴的package包/類
/**
* 為DrawerLayout 布局設置狀態欄變色
*
* @param activity 需要設置的activity
* @param drawerLayout DrawerLayout
* @param color 狀態欄顏色值
* @param statusBarAlpha 狀態欄透明度
*/
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color, int statusBarAlpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
// 生成一個狀態欄大小的矩形
View statusBarView = createStatusBarView(activity, color);
// 添加 statusBarView 到布局中
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
contentLayout.addView(statusBarView, 0);
// 內容布局不是 LinearLayout 時,設置padding top
if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
}
// 設置屬性
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawerLayout.setFitsSystemWindows(false);
contentLayout.setFitsSystemWindows(false);
contentLayout.setClipToPadding(true);
drawer.setFitsSystemWindows(false);
addTranslucentView(activity, statusBarAlpha);
}