Java Code Examples for android.app.Activity#getWindow()
The following examples show how to use
android.app.Activity#getWindow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusBarCompat.java From Common with Apache License 2.0 | 6 votes |
public static void cancelLightStatusBar(@NonNull Activity activity) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return; } if (activity == null) { return; } Window window = activity.getWindow(); if (window == null) { return; } View decorView = window.getDecorView(); if (decorView == null) { return; } decorView.setSystemUiVisibility(decorView.getSystemUiVisibility() & (~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)); }
Example 2
Source File: StatusBarUtil.java From APlayer with GNU General Public License v3.0 | 6 votes |
/** * 设置状态栏全透明 * * @param activity 需要设置的activity */ public static void setTransparent(Activity activity) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || activity == null) { return; } Window window = activity.getWindow(); //4.4 全透明状态栏 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } //5.0 全透明实现 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); int systemUiVisibility = activity.getWindow().getDecorView().getSystemUiVisibility(); systemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; systemUiVisibility |= SYSTEM_UI_FLAG_LAYOUT_STABLE; window.getDecorView().setSystemUiVisibility(systemUiVisibility); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); } }
Example 3
Source File: ScreenUtils.java From FamilyChat with Apache License 2.0 | 6 votes |
/** * 5.0以上切换NavigationBar颜色 * !!!注意!!!需要在Activity的onCreate()之前调用以下方法 */ public static void changeNavigationBarColor(Activity activity, int color) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = activity.getWindow(); window.requestFeature(Window.FEATURE_NO_TITLE); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setNavigationBarColor(color);//切换导航栏颜色 } }
Example 4
Source File: ScreenUtils.java From SprintNBA with Apache License 2.0 | 6 votes |
/** * 调整窗口的透明度 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(); }
Example 5
Source File: Tinter.java From NineGridLayout with Apache License 2.0 | 6 votes |
@TargetApi(19) private static void tint(Activity activity, boolean on) { Window win = activity.getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); Class<? extends Window> clazz = win.getClass(); try { Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); int darkModeFlag = field.getInt(layoutParams); Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); extraFlagField.invoke(win, darkModeFlag, darkModeFlag); } catch (Throwable e) { } }
Example 6
Source File: EditPage.java From AndroidLinkup with GNU General Public License v2.0 | 5 votes |
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); } }
Example 7
Source File: KugouLayout.java From KugouLayout with MIT License | 5 votes |
private void attachToContent(Activity activity, KugouLayout kugouLayout){ Window window = activity.getWindow(); ViewGroup decorView = (ViewGroup)window.getDecorView(); ViewGroup decorChild= (ViewGroup)decorView.getChildAt(0); decorView.removeAllViews(); mKugouLayout.mContentContainer.addView(decorChild, decorChild.getLayoutParams()); decorView.addView(mKugouLayout, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); window.setBackgroundDrawable(new ColorDrawable(0x0)); }
Example 8
Source File: SystemUtils.java From EasyPhotos with Apache License 2.0 | 5 votes |
private void setStatusTextBlackAndroid(Activity activity, boolean darkmode) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Window window = activity.getWindow(); if (darkmode) { window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } else { int flag = window.getDecorView().getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; window.getDecorView().setSystemUiVisibility(flag); } } }
Example 9
Source File: SystemBarHelper.java From LeisureRead with Apache License 2.0 | 5 votes |
/** * 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); }
Example 10
Source File: SystemBarUtils.java From MarkdownEditors with Apache License 2.0 | 5 votes |
/** * 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); }
Example 11
Source File: StatusBarUtils.java From KUtils with Apache License 2.0 | 5 votes |
public static void setFullScreen(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = activity.getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(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); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 设置透明状态栏,这样才能让 ContentView 向上 activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } }
Example 12
Source File: Shake2Share.java From BigApp_WordPress_Android with Apache License 2.0 | 5 votes |
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); } }
Example 13
Source File: Util.java From androidnative.pri with Apache License 2.0 | 5 votes |
static void setFullScreen(Map message) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ) { return; } final Boolean value = (Boolean) message.get("value"); final Activity activity = QtNative.activity(); Runnable runnable = new Runnable () { public void run() { Window w = activity.getWindow(); // in Activity's onCreate() for instance View decorView = w.getDecorView(); int config = decorView.getSystemUiVisibility(); if (value) { config &= ~View.SYSTEM_UI_FLAG_FULLSCREEN; } else { config |= View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } decorView.setSystemUiVisibility(config); } }; activity.runOnUiThread(runnable); }
Example 14
Source File: EyesKitKat.java From MeiBaseModule with Apache License 2.0 | 5 votes |
static void setStatusBarColor(Activity activity, int statusColor) { Window window = activity.getWindow(); //设置Window为全透明 window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); //获取父布局 View mContentChild = mContentView.getChildAt(0); //获取状态栏高度 int statusBarHeight = getStatusBarHeight(activity); //如果已经存在假状态栏则移除,防止重复添加 removeFakeStatusBarViewIfExist(activity); //添加一个View来作为状态栏的填充 addFakeStatusBarView(activity, statusColor, statusBarHeight); //设置子控件到状态栏的间距 addMarginTopToContentChild(mContentChild, statusBarHeight); //不预留系统栏位置 if (mContentChild != null) { ViewCompat.setFitsSystemWindows(mContentChild, false); } //如果在Activity中使用了ActionBar则需要再将布局与状态栏的高度跳高一个ActionBar的高度,否则内容会被ActionBar遮挡 int action_bar_id = activity.getResources().getIdentifier("action_bar", "id", activity.getPackageName()); View view = activity.findViewById(action_bar_id); if (view != null) { TypedValue typedValue = new TypedValue(); if (activity.getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) { int actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources() .getDisplayMetrics()); Eyes.setContentTopPadding(activity, actionBarHeight); } } }
Example 15
Source File: ActivityUtils.java From MVPAndroidBootstrap with Apache License 2.0 | 5 votes |
/** * Force screen to turn on if the phone is asleep. * * @param context The current Context or Activity that this method is called from */ public static void turnScreenOn(Activity context) { try { Window window = context.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); } catch (Exception ex) { Log.e("PercolateAndroidUtils", "Unable to turn on screen for activity " + context); } }
Example 16
Source File: SystemBarTintManager.java From Noyze with Apache License 2.0 | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(Build.VERSION_CODES.KITKAT) public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }
Example 17
Source File: StatusBarCompat.java From GalleryLayoutManager with Apache License 2.0 | 4 votes |
/** * change to full screen mode * @param hideStatusBarBackground hide status bar alpha Background when SDK > 21, true if hide it */ public static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); ViewGroup mContentView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int statusBarHeight = getStatusBarHeight(activity); //First translucent status bar. window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //set child View not fill the system window View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); //must call requestApplyInsets, otherwise it will have space in screen bottom ViewCompat.requestApplyInsets(mChildView); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //After LOLLIPOP just set LayoutParams. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(COLOR_TRANSLUCENT); } else { window.setStatusBarColor(calculateStatusBarColor(COLOR_TRANSLUCENT, DEFAULT_COLOR_ALPHA)); } } else { ViewGroup mDecorView = (ViewGroup) window.getDecorView(); if (mDecorView.getTag() != null && mDecorView.getTag() instanceof Boolean && (Boolean) mDecorView.getTag()) { mChildView = mDecorView.getChildAt(0); //remove fake status bar view. mDecorView.removeView(mChildView); mChildView = mContentView.getChildAt(0); if (mChildView != null) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams(); //cancel the margin top if (lp != null && lp.topMargin >= statusBarHeight) { lp.topMargin -= statusBarHeight; mChildView.setLayoutParams(lp); } } mDecorView.setTag(false); } } } }
Example 18
Source File: SystemBarTintManager.java From V2EX with GNU General Public License v3.0 | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(19) public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }
Example 19
Source File: SystemBarTintManager.java From FireFiles with Apache License 2.0 | 4 votes |
/** * Constructor. Call this in the host activity onCreate method after its * content view has been set. You should always create new instances when * the host activity is recreated. * * @param activity The host activity. */ @TargetApi(19) public SystemBarTintManager(Activity activity) { Window win = activity.getWindow(); ViewGroup decorViewGroup = (ViewGroup) win.getDecorView(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // check theme attrs int[] attrs = {android.R.attr.windowTranslucentStatus, android.R.attr.windowTranslucentNavigation}; TypedArray a = activity.obtainStyledAttributes(attrs); try { mStatusBarAvailable = a.getBoolean(0, false); //mNavBarAvailable = a.getBoolean(1, false); } finally { a.recycle(); } // check window flags WindowManager.LayoutParams winParams = win.getAttributes(); int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if ((winParams.flags & bits) != 0) { mStatusBarAvailable = true; } bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if ((winParams.flags & bits) != 0) { mNavBarAvailable = true; } } mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable); // device might not have virtual navigation keys if (!mConfig.hasNavigtionBar()) { mNavBarAvailable = false; } if (mStatusBarAvailable) { setupStatusBarView(activity, decorViewGroup); } if (mNavBarAvailable) { setupNavBarView(activity, decorViewGroup); } }
Example 20
Source File: SkinStatusBarUtils.java From Android-skin-support with MIT License | 2 votes |
/** * 沉浸式状态栏。 * 支持 4.4 以上版本的 MIUI 和 Flyme,以及 5.0 以上版本的其他 Android。 * * @param activity 需要被设置沉浸式状态栏的 Activity。 */ public static void translucent(Activity activity, @ColorInt int colorOn5x) { Window window = activity.getWindow(); translucent(window, colorOn5x); }