android.view.Window#getDecorView ( )源码实例Demo

下面列出了android.view.Window#getDecorView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidUtilCode   文件: BarUtils.java
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;
}
 
源代码2 项目: ticdesign   文件: WindowUtils.java
/**
 * 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;
}
 
源代码3 项目: simple-keyboard   文件: LatinIME.java
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);
        }
    }
}
 
@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;
}
 
源代码5 项目: mollyim-android   文件: WindowUtil.java
private static void clearSystemUiFlags(@NonNull Window window, int flags) {
  View view    = window.getDecorView();
  int  uiFlags = view.getSystemUiVisibility();

  uiFlags &= ~flags;
  view.setSystemUiVisibility(uiFlags);
}
 
源代码6 项目: AndroidUtilCode   文件: KeyboardUtils.java
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;
}
 
源代码7 项目: SwipeAwayDialog   文件: SwipeAwayDialogFragment.java
@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;
    }
}
 
源代码8 项目: MeiBaseModule   文件: EyesKitKat.java
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;
}
 
源代码9 项目: Android-skin-support   文件: SkinStatusBarUtils.java
/**
 * 设置状态栏字体图标为深色,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;
}
 
源代码10 项目: SwipeAwayDialog   文件: SwipeAwayDialogFragment.java
@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;
    }
}
 
源代码11 项目: Telegram-FOSS   文件: AndroidUtilities.java
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);
    }
}
 
源代码12 项目: Auth0.Android   文件: WebAuthActivity.java
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);
    }
}
 
源代码13 项目: pandora   文件: ViewKnife.java
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);
    }
}
 
源代码14 项目: Material-SearchView   文件: SearchView.java
@Nullable
private View getDecorView() {
    Dialog dialog = getDialog();
    if (dialog != null) {
        Window window = dialog.getWindow();
        if (window != null) {
            return window.getDecorView();
        }
    }
    return null;
}
 
源代码15 项目: FireFiles   文件: SystemBarTintManager.java
/**
 * 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);
    }

}
 
源代码16 项目: DialogUtil   文件: WindowAdjuster.java
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);*/

}
 
源代码17 项目: FireFiles   文件: SystemBarTintManager.java
/**
 * 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);
    }

}
 
源代码18 项目: imsdk-android   文件: SystemBarTintManager.java
/**
 * 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);
    }

}
 
源代码19 项目: school_shop   文件: SystemBarTintManager.java
/**
 * 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);
    }

}
 
源代码20 项目: Android-utils   文件: BarUtils.java
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);
}