当前位置: 首页>>代码示例>>Java>>正文


Java DrawerLayout.setFitsSystemWindows方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:joelan,项目名称:ClouldReader,代码行数:33,代码来源:StatusBarUtil.java

示例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);
    }
}
 
开发者ID:stytooldex,项目名称:stynico,代码行数:23,代码来源:StatusBarUtil.java

示例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);
    }
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:29,代码来源:BarUtils.java

示例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);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:32,代码来源:BarUtils.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:HomeActivity.java

示例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);
    }
}
 
开发者ID:Ayvytr,项目名称:EasyAndroid,代码行数:26,代码来源:BarTool.java

示例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);
    }
}
 
开发者ID:squareboat,项目名称:Excuser,代码行数:28,代码来源:StatusBarUtil.java

示例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);
}
 
开发者ID:WeDevelopTeam,项目名称:HeroVideo-master,代码行数:46,代码来源:SystemBarHelper.java

示例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);
}
 
开发者ID:Lingzh0ng,项目名称:BrotherWeather,代码行数:14,代码来源:XStatusBar.java

示例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);
}
 
开发者ID:imliujun,项目名称:LJFramework,代码行数:37,代码来源:StatusBarUtil.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:StatusBarUtil.java


注:本文中的android.support.v4.widget.DrawerLayout.setFitsSystemWindows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。