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


Java Activity.getWindow方法代码示例

本文整理汇总了Java中android.app.Activity.getWindow方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.getWindow方法的具体用法?Java Activity.getWindow怎么用?Java Activity.getWindow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Activity的用法示例。


在下文中一共展示了Activity.getWindow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setWindowStatusBarColor

import android.app.Activity; //导入方法依赖的package包/类
/**
     * 当前页面设置状态栏颜色
     *
     * */
    public static void setWindowStatusBarColor(Activity activity, int color){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
            View view=contentView.getChildAt(1);
            view.setBackgroundColor(color);
        } else {
            Window window=activity.getWindow();
            if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.LOLLIPOP){
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//            状态栏
                window.setStatusBarColor(color);
//            底部导航栏
                window.setNavigationBarColor(color);
            }
        }


    }
 
开发者ID:ifadai,项目名称:AndroidThemeChange,代码行数:23,代码来源:ThemeUtils.java

示例2: dimBackground

import android.app.Activity; //导入方法依赖的package包/类
/**
 * 调整窗口的透明度  1.0f,0.5f 变暗
 *
 * @param from    from>=0&&from<=1.0f
 * @param to      to>=0&&to<=1.0f
 * @param context 当前的activity
 */
public static void dimBackground(final float from, final float to, Activity context) {
    final Window window = context.getWindow();
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
    valueAnimator.setDuration(500);
    valueAnimator.addUpdateListener(
            new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    WindowManager.LayoutParams params
                            = window.getAttributes();
                    params.alpha = (Float) animation.getAnimatedValue();
                    window.setAttributes(params);
                }
            });
    valueAnimator.start();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:WindowUtils.java

示例3: setWindowBrightness

import android.app.Activity; //导入方法依赖的package包/类
/**
 * 设置给定Activity的窗口的亮度(可以看到效果,但系统的亮度属性不会改变)
 *
 * @param activity         要通过此Activity来设置窗口的亮度
 * @param screenBrightness 亮度,范围是0-255
 */
public static void setWindowBrightness(Activity activity, float screenBrightness) {
    float brightness = screenBrightness;
    if (screenBrightness < 1) {
        brightness = 1;
    } else if (screenBrightness > 255) {
        brightness = screenBrightness % 255;
        if (brightness == 0) {
            brightness = 255;
        }
    }
    Window window = activity.getWindow();
    WindowManager.LayoutParams localLayoutParams = window.getAttributes();
    localLayoutParams.screenBrightness = (float) brightness / 255;
    window.setAttributes(localLayoutParams);
}
 
开发者ID:RockyQu,项目名称:MVVMFrames,代码行数:22,代码来源:DeviceUtils.java

示例4: setStatusBarColor

import android.app.Activity; //导入方法依赖的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);
    }
}
 
开发者ID:bigjelly,项目名称:AndFast,代码行数:19,代码来源:EyesLollipop.java

示例5: setActivity

import android.app.Activity; //导入方法依赖的package包/类
public void setActivity(Activity activity) {
	super.setActivity(activity);
	int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
	if (resId > 0) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window win = activity.getWindow();
		win.setBackgroundDrawableResource(resId);
	}
}
 
开发者ID:liupengandroid,项目名称:ywApplication,代码行数:11,代码来源:Shake2Share.java

示例6: setStatusBarColor

import android.app.Activity; //导入方法依赖的package包/类
/**
 * можем изменять цвет статус бара сверху (нужно там где его делаю прозрачным)
 *
 * @param colorId - собственно цвет
 */
public static void setStatusBarColor(@Nullable Activity activity, @ColorRes int colorId) {
    if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ContextCompat.getColor(activity, colorId));
    }
}
 
开发者ID:interactiveservices,项目名称:utils-android,代码行数:13,代码来源:UiUtils.java

示例7: setStatusBarColor

import android.app.Activity; //导入方法依赖的package包/类
/**
     * 修改状态栏颜色,支持4.4以上版本
     * @param activity
     * @param colorId
     */
    public static void setStatusBarColor(Activity activity, int colorId) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = activity.getWindow();
//      window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(activity.getResources().getColor(colorId));
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //使用SystemBarTint库使4.4版本状态栏变色,需要先将状态栏设置为透明
            transparencyBar(activity);
            SystemBarTintManager tintManager = new SystemBarTintManager(activity);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(colorId);
        }
    }
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:20,代码来源:StatusBarUtil.java

示例8: setTranslucentStatus

import android.app.Activity; //导入方法依赖的package包/类
public static void setTranslucentStatus(Activity activity,int statusBarPlaceColor) {

        // 5.0以上系统状态栏透明
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = activity.getWindow();
            //window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //window.setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }
 
开发者ID:hss01248,项目名称:MainActivityUIUtil,代码行数:16,代码来源:StatusbarUtil.java

示例9: setStatusBarColor

import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setStatusBarColor(Activity activity, int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        if (color == Color.BLACK
                && window.getNavigationBarColor() == Color.BLACK) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        } else {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        }
        window.setStatusBarColor(color);
    }
}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:14,代码来源:Utility.java

示例10: tintStatusBarForDrawer

import android.app.Activity; //导入方法依赖的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:MUFCRyan,项目名称:BilibiliClient,代码行数:46,代码来源:SystemBarHelper.java

示例11: setActivity

import android.app.Activity; //导入方法依赖的package包/类
public void setActivity(Activity activity) {
	super.setActivity(activity);
	Window win = activity.getWindow();
	int orientation = activity.getResources().getConfiguration().orientation;
	if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	} else {
		win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
				| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
	}
}
 
开发者ID:liupengandroid,项目名称:ywApplication,代码行数:13,代码来源:EditPage.java

示例12: TpSbNNbwFCImmerseMode

import android.app.Activity; //导入方法依赖的package包/类
public TpSbNNbwFCImmerseMode(@NonNull Activity activity) {
    mActivityRef = new SoftReference<>(activity);

    Window window = activity.getWindow();
    WindowUtils.clearWindowFlags(window, FLAG_TRANSLUCENT_STATUS);
    WindowUtils.clearWindowFlags(window, FLAG_TRANSLUCENT_NAVIGATION);
    WindowUtils.addWindowFlags(window, FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

    window.getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_STABLE | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

    mCompatStatusBarView = setupContentViewAndStatusBarView(activity);

    window.setStatusBarColor(Color.TRANSPARENT);
    mCompatStatusBarView.setBackgroundColor(Color.TRANSPARENT);
}
 
开发者ID:ls1110924,项目名称:ImmerseMode,代码行数:16,代码来源:TpSbNNbwFCImmerseMode.java

示例13: addFakeStatusBarView

import android.app.Activity; //导入方法依赖的package包/类
/**
 * 1. Add fake statusBarView.
 * 2. set tag to statusBarView.
 */
private static View addFakeStatusBarView(Activity activity, int statusBarColor, int statusBarHeight) {
    Window window = activity.getWindow();
    ViewGroup mDecorView = (ViewGroup) window.getDecorView();

    View mStatusBarView = new View(activity);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight);
    layoutParams.gravity = Gravity.TOP;
    mStatusBarView.setLayoutParams(layoutParams);
    mStatusBarView.setBackgroundColor(statusBarColor);
    mStatusBarView.setTag(TAG_FAKE_STATUS_BAR_VIEW);

    mDecorView.addView(mStatusBarView);
    return mStatusBarView;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:StatusBarCompatKitKat.java

示例14: invasionStatusBar

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Set the content layout full the StatusBar, but do not hide StatusBar.
 */
public static void invasionStatusBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        View decorView = window.getDecorView();
        decorView.setSystemUiVisibility(decorView.getSystemUiVisibility()
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
    }
}
 
开发者ID:yanzhenjie,项目名称:Sofia,代码行数:15,代码来源:Utils.java

示例15: setStatusBarColorForCollapsingToolbar

import android.app.Activity; //导入方法依赖的package包/类
/**
     * compat for CollapsingToolbarLayout
     * 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
     * 2. set FitsSystemWindows for views.
     * 3. removeFakeStatusBarViewIfExist
     * 4. removeMarginTopOfContentChild
     * 5. add OnOffsetChangedListener to change statusBarView's alpha
     */
    public static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout,
                                                             Toolbar toolbar, int statusColor) {
        Window window = activity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);

        View mContentChild = mContentView.getChildAt(0);
        mContentChild.setFitsSystemWindows(false);
        ((View) appBarLayout.getParent()).setFitsSystemWindows(false);
        appBarLayout.setFitsSystemWindows(false);
        collapsingToolbarLayout.setFitsSystemWindows(false);
        collapsingToolbarLayout.getChildAt(0).setFitsSystemWindows(false);

        toolbar.setFitsSystemWindows(true);
        if (toolbar.getTag() == null) {
            CollapsingToolbarLayout.LayoutParams lp = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
            lp.height += getStatusBarHeight(activity);
            toolbar.setLayoutParams(lp);
            toolbar.setTag(true);
        }

        int statusBarHeight = getStatusBarHeight(activity);
        removeFakeStatusBarViewIfExist(activity);
        removeMarginTopOfContentChild(mContentChild, statusBarHeight);
//        final View statusView = addFakeStatusBarView(activity, statusColor, statusBarHeight);
//        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
//            @Override
//            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
//                if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getStatusBarScrim().getIntrinsicHeight()) {
//                    if (statusView.getAlpha() == 0) {
//                        statusView.animate().alpha(1f).setDuration(collapsingToolbarLayout.getScrollBarFadeDuration()).start();
//                    }
//                } else {
//                    statusView.setAlpha(0);
//                }
//            }
//        });
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:47,代码来源:StatusBarCompatKitKat.java


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