Java Code Examples for android.view.Window#getDecorView()
The following examples show how to use
android.view.Window#getDecorView() .
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: MaterialAlertDialogBuilder.java From material-components-android with Apache License 2.0 | 6 votes |
@NonNull @Override public AlertDialog create() { AlertDialog alertDialog = super.create(); Window window = alertDialog.getWindow(); /* {@link Window#getDecorView()} should be called before any changes are made to the Window * as it locks in attributes and affects layout. */ View decorView = window.getDecorView(); if (background instanceof MaterialShapeDrawable) { ((MaterialShapeDrawable) background).setElevation(ViewCompat.getElevation(decorView)); } Drawable insetDrawable = MaterialDialogs.insetDrawable(background, backgroundInsets); window.setBackgroundDrawable(insetDrawable); decorView.setOnTouchListener(new InsetDialogOnTouchListener(alertDialog, backgroundInsets)); return alertDialog; }
Example 2
Source File: BarUtils.java From AndroidUtilCode with Apache License 2.0 | 6 votes |
private static View applyStatusBarColor(final Window window, final int color, boolean isDecor) { ViewGroup parent = isDecor ? (ViewGroup) window.getDecorView() : (ViewGroup) window.findViewById(android.R.id.content); View fakeStatusBarView = parent.findViewWithTag(TAG_STATUS_BAR); if (fakeStatusBarView != null) { if (fakeStatusBarView.getVisibility() == View.GONE) { fakeStatusBarView.setVisibility(View.VISIBLE); } fakeStatusBarView.setBackgroundColor(color); } else { fakeStatusBarView = createStatusBarView(window.getContext(), color); parent.addView(fakeStatusBarView); } return fakeStatusBarView; }
Example 3
Source File: LatinIME.java From simple-keyboard with Apache License 2.0 | 6 votes |
private void setNavigationBarColor() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && mSettings.getCurrent().mUseMatchingNavbarColor) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final int keyboardColor = Settings.readKeyboardColor(prefs, this); final Window window = getWindow().getWindow(); if (window == null) { return; } mOriginalNavBarColor = window.getNavigationBarColor(); window.setNavigationBarColor(keyboardColor); final View view = window.getDecorView(); mOriginalNavBarFlags = view.getSystemUiVisibility(); if (ResourceUtils.isBrightColor(keyboardColor)) { view.setSystemUiVisibility(mOriginalNavBarFlags | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); } else { view.setSystemUiVisibility(mOriginalNavBarFlags & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); } } }
Example 4
Source File: WindowUtils.java From ticdesign with Apache License 2.0 | 6 votes |
/** * Clip given window to round. * * This method should be called before window is show. * * @param window window needs to be clipped. * @return If clip succeed. */ public static boolean clipToScreenShape(final Window window) { if (window == null || window.getDecorView() == null) { return false; } // Record original drawable & set window to transparent to avoid window has solid color. final Drawable original = window.getDecorView().getBackground(); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.getDecorView().setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { // Delay setting window background when shape is defined. Drawable background = getBackgroundDrawable(original, insets.isRound()); window.setBackgroundDrawable(background); if (insets.isRound()) { clipToRound(v); } return insets; } }); window.getDecorView().requestApplyInsets(); return true; }
Example 5
Source File: SkinStatusBarUtils.java From Android-skin-support with MIT License | 5 votes |
/** * 设置状态栏字体图标为深色,Android 6 * * @param window 需要设置的窗口 * @param light 是否把状态栏字体及图标颜色设置为深色 * @return boolean 成功执行返回true */ @TargetApi(23) private static boolean Android6SetStatusBarLightMode(Window window, boolean light) { View decorView = window.getDecorView(); int systemUi = light ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : View.SYSTEM_UI_FLAG_LAYOUT_STABLE; systemUi = changeStatusBarModeRetainFlag(window, systemUi); decorView.setSystemUiVisibility(systemUi); if (SkinDeviceUtils.isMIUIV9()) { // MIUI 9 低于 6.0 版本依旧只能回退到以前的方案 // https://github.com/Tencent/QMUI_Android/issues/160 MIUISetStatusBarLightMode(window, light); } return true; }
Example 6
Source File: SearchView.java From Material-SearchView with Apache License 2.0 | 5 votes |
@Nullable private View getDecorView() { Dialog dialog = getDialog(); if (dialog != null) { Window window = dialog.getWindow(); if (window != null) { return window.getDecorView(); } } return null; }
Example 7
Source File: ViewKnife.java From pandora with Apache License 2.0 | 5 votes |
public static void transStatusBar(@NonNull Window window) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { View view = window.getDecorView(); if (view != null) { view.setSystemUiVisibility(view.getSystemUiVisibility() | 1280); } } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } }
Example 8
Source File: WebAuthActivity.java From Auth0.Android with MIT License | 5 votes |
private void setFullscreenMode() { Log.d(TAG, "Activity in fullscreen mode"); final Window window = getWindow(); if (Build.VERSION.SDK_INT >= 16) { View decorView = window.getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } else { window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } }
Example 9
Source File: AndroidUtilities.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public static void setLightNavigationBar(Window window, boolean enable) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { final View decorView = window.getDecorView(); int flags = decorView.getSystemUiVisibility(); if (enable) { flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; } else { flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; } decorView.setSystemUiVisibility(flags); } }
Example 10
Source File: SwipeAwayDialogFragment.java From SwipeAwayDialog with MIT License | 5 votes |
@Override public void onStart() { super.onStart(); if (!mSwipeLayoutGenerated && getShowsDialog()) { Window window = getDialog().getWindow(); ViewGroup decorView = (ViewGroup)window.getDecorView(); View content = decorView.getChildAt(0); decorView.removeView(content); SwipeableFrameLayout layout = new SwipeableFrameLayout(getActivity()); layout.addView(content); decorView.addView(layout); mListener = new SwipeDismissTouchListener(decorView, "layout", new SwipeDismissTouchListener.DismissCallbacks() { @Override public boolean canDismiss(Object token) { return isCancelable() && mSwipeable; } @Override public void onDismiss(View view, boolean toRight, Object token) { if (!onSwipedAway(toRight)) { dismiss(); } } }); mListener.setTiltEnabled(mTiltEnabled); layout.setSwipeDismissTouchListener(mListener); layout.setOnTouchListener(mListener); layout.setClickable(true); mSwipeLayoutGenerated = true; } }
Example 11
Source File: WindowUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
private static void clearSystemUiFlags(@NonNull Window window, int flags) { View view = window.getDecorView(); int uiFlags = view.getSystemUiVisibility(); uiFlags &= ~flags; view.setSystemUiVisibility(uiFlags); }
Example 12
Source File: EyesKitKat.java From MeiBaseModule with Apache License 2.0 | 5 votes |
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; }
Example 13
Source File: SwipeAwayDialogFragment.java From SwipeAwayDialog with MIT License | 5 votes |
@Override public void onStart() { super.onStart(); if (!mSwipeLayoutGenerated && getShowsDialog()) { Window window = getDialog().getWindow(); ViewGroup decorView = (ViewGroup)window.getDecorView(); View content = decorView.getChildAt(0); decorView.removeView(content); SwipeableFrameLayout layout = new SwipeableFrameLayout(getActivity()); layout.addView(content); decorView.addView(layout); mListener = new SwipeDismissTouchListener(decorView, "layout", new SwipeDismissTouchListener.DismissCallbacks() { @Override public boolean canDismiss(Object token) { return isCancelable() && mSwipeable; } @Override public void onDismiss(View view, boolean toRight, Object token) { if (!onSwipedAway(toRight)) { dismiss(); } } }); mListener.setTiltEnabled(mTiltEnabled); layout.setSwipeDismissTouchListener(mListener); layout.setOnTouchListener(mListener); layout.setClickable(true); mSwipeLayoutGenerated = true; } }
Example 14
Source File: KeyboardUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
private static int getDecorViewInvisibleHeight(@NonNull final Window window) { final View decorView = window.getDecorView(); final Rect outRect = new Rect(); decorView.getWindowVisibleDisplayFrame(outRect); Log.d("KeyboardUtils", "getDecorViewInvisibleHeight: " + (decorView.getBottom() - outRect.bottom)); int delta = Math.abs(decorView.getBottom() - outRect.bottom); if (delta <= UtilsBridge.getNavBarHeight() + UtilsBridge.getStatusBarHeight()) { sDecorViewDelta = delta; return 0; } return delta - sDecorViewDelta; }
Example 15
Source File: SystemBarTintManager.java From imsdk-android with MIT License | 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) @SuppressWarnings("ResourceType") 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 16
Source File: SystemBarTintManager.java From school_shop with MIT License | 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 17
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 18
Source File: BarUtils.java From Android-utils with Apache License 2.0 | 4 votes |
private static void hideStatusBarView(final Window window) { ViewGroup decorView = (ViewGroup) window.getDecorView(); View fakeStatusBarView = decorView.findViewWithTag(TAG_STATUS_BAR); if (fakeStatusBarView == null) return; fakeStatusBarView.setVisibility(View.GONE); }
Example 19
Source File: WindowAdjuster.java From DialogUtil with Apache License 2.0 | 4 votes |
private static void adjustSize(Window window, ConfigBean bean) { View rootView = window.getDecorView(); //window.setWindowAnimations(R.style.dialog_center); WindowManager.LayoutParams wl = window.getAttributes(); int width = window.getWindowManager().getDefaultDisplay().getWidth(); int height = window.getWindowManager().getDefaultDisplay().getHeight(); int measuredHeight = rootView.getMeasuredHeight(); int measuredWidth = rootView.getMeasuredWidth(); float widthRatio = 0f; float heightRatio = 0f; if(width > height){//宽屏 widthRatio = 0.5f; } /*float widthRatio = 0.85f; float heightRatio = 0f; if(bean.type ==DefaultConfig.TYPE_IOS_BOTTOM){ widthRatio = 0.95f; }else if(bean.type ==DefaultConfig.TYPE_IOS_CENTER_LIST){ widthRatio = 0.9f; } if(width > height){//宽屏 widthRatio = 0.5f; }*/ //set ratio as user has set if(bean.maxWidthPercent > 0 && measuredWidth > bean.maxWidthPercent * width){ widthRatio = bean.maxWidthPercent; } if(bean.forceWidthPercent >0 && bean.forceWidthPercent <=1.0f){ widthRatio = bean.forceWidthPercent; } if(bean.maxHeightPercent> 0 && measuredHeight > bean.maxHeightPercent * height){ heightRatio = bean.maxHeightPercent; } if(bean.forceHeightPercent >0 && bean.forceHeightPercent <=1.0f){ heightRatio = bean.forceHeightPercent; } boolean needUpdate = false; if(widthRatio >0){ wl.width = (int) (width * widthRatio);//stretch when the content is not enough,margin when the content is full fill the screen needUpdate = true; } //if (measuredHeight > height* heightRatio){//only work when the content is full fill the screen if(heightRatio>0){ wl.height = (int) (height* heightRatio); needUpdate = true; } if(needUpdate){ window.setAttributes(wl); } /*if(Tool.istheTypeOfNotAdjust(bean)){ *//*wl.width = ViewGroup.LayoutParams.WRAP_CONTENT; wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;*//* }else { // rootView.setPadding(0,30,0,30); if(widthRatio >0){ wl.width = (int) (width * widthRatio);//stretch when the content is not enough,margin when the content is full fill the screen } //if (measuredHeight > height* heightRatio){//only work when the content is full fill the screen if(heightRatio>0){ wl.height = (int) (height* heightRatio); } if(bean.type == DefaultConfig.TYPE_BOTTOM_SHEET_GRID && !bean.hasBehaviour){ wl.height =measuredHeight; } // } } window.setAttributes(wl);*/ }
Example 20
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); } }