android.view.Window.getWindowManager()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中android.view.Window.getWindowManager()方法的一些代码示例,展示了Window.getWindowManager()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.getWindowManager()方法的具体详情如下:
包路径:android.view.Window
类名称:Window
方法名:getWindowManager

Window.getWindowManager介绍

暂无

代码示例

代码示例来源:origin: aurelhubert/ahbottomnavigation

/**
 * Get the height of the buttons bar
 *
 * @param context Context
 * @return
 */
public static int getSoftButtonsBarSizePort(Context context) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    DisplayMetrics metrics = new DisplayMetrics();
    Window window = unwrap(context).getWindow();
    window.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int usableHeight = metrics.heightPixels;
    window.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
    int realHeight = metrics.heightPixels;
    if (realHeight > usableHeight)
      return realHeight - usableHeight;
    else
      return 0;
  }
  return 0;
}

代码示例来源:origin: bingoogolapple/BGASwipeBackLayout-Android

/**
   * 手机具有底部导航栏时,底部导航栏是否可见
   */
  private static boolean isNavigationBarVisible(Activity activity) {
//        View decorView = activity.getWindow().getDecorView();
//        return (decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 2;

    boolean show = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      Display display = activity.getWindow().getWindowManager().getDefaultDisplay();
      Point point = new Point();
      display.getRealSize(point);
      View decorView = activity.getWindow().getDecorView();
      Configuration conf = activity.getResources().getConfiguration();
      if (Configuration.ORIENTATION_LANDSCAPE == conf.orientation) {
        View contentView = decorView.findViewById(android.R.id.content);
        if (contentView != null) {
          show = (point.x != contentView.getWidth());
        }
      } else {
        Rect rect = new Rect();
        decorView.getWindowVisibleDisplayFrame(rect);
        show = (rect.bottom != point.y);
      }
    }
    return show;
  }

代码示例来源:origin: jeasonlzy/NineGridView

if (width == 0) {
  DisplayMetrics dm = new DisplayMetrics();
  window.getWindowManager().getDefaultDisplay().getMetrics(dm);
  width = (int) ((dm.widthPixels) * 0.9);// 宽度height =

代码示例来源:origin: stackoverflow.com

public static void positionToast(Toast toast, View view, Window window, int offsetX, int offsetY) {
  // toasts are positioned relatively to decor view, views relatively to their parents, we have to gather additional data to have a common coordinate system
  Rect rect = new Rect();
  window.getDecorView().getWindowVisibleDisplayFrame(rect);
  // covert anchor view absolute position to a position which is relative to decor view
  int[] viewLocation = new int[2];
  view.getLocationInWindow(viewLocation);
  int viewLeft = viewLocation[0] - rect.left;
  int viewTop = viewLocation[1] - rect.top;

  // measure toast to center it relatively to the anchor view
  DisplayMetrics metrics = new DisplayMetrics();
  window.getWindowManager().getDefaultDisplay().getMetrics(metrics);
  int widthMeasureSpec = MeasureSpec.makeMeasureSpec(metrics.widthPixels, MeasureSpec.UNSPECIFIED);
  int heightMeasureSpec = MeasureSpec.makeMeasureSpec(metrics.heightPixels, MeasureSpec.UNSPECIFIED);
  toast.getView().measure(widthMeasureSpec, heightMeasureSpec);
  int toastWidth = toast.getView().getMeasuredWidth();

  // compute toast offsets
  int toastX = viewLeft + (view.getWidth() - toastWidth) / 2 + offsetX;
  int toastY = viewTop + view.getHeight() + offsetY;

  toast.setGravity(Gravity.LEFT | Gravity.TOP, toastX, toastY);
}

代码示例来源:origin: multidots/android-app-common-tasks

setUpWebView();
Display display = getWindow().getWindowManager().getDefaultDisplay();
final float scale = getContext().getResources().getDisplayMetrics().density;
int orientation = getContext().getResources().getConfiguration().orientation;

代码示例来源:origin: multidots/android-app-common-tasks

setUpWebView();
Display display = getWindow().getWindowManager().getDefaultDisplay();
final float scale = getContext().getResources().getDisplayMetrics().density;
int orientation = getContext().getResources().getConfiguration().orientation;

代码示例来源:origin: eneim/toro

getWindow().getWindowManager().getDefaultDisplay().getSize(windowSize);
boolean landscape = windowSize.y < windowSize.x;

代码示例来源:origin: zcolin/ZEasyPR

/**
 * 获取当前窗口的高度, 该高度是不包含导航栏和状态栏的
 */
public static int getWindowHeight(Activity activity) {
  return activity.getWindow()
          .getWindowManager()
          .getDefaultDisplay()
          .getHeight();
}

代码示例来源:origin: nileshpambhar/MultiPhotoPicker

public static DisplayMetrics getDisplayInfo(Activity activity) {
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindow().getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm;
  }
}

代码示例来源:origin: nileshpambhar/MultiPhotoPicker

public static DisplayMetrics getDisplayInfo(Activity activity) {
  DisplayMetrics dm = new DisplayMetrics();
  activity.getWindow().getWindowManager().getDefaultDisplay().getMetrics(dm);
  return dm;
}

代码示例来源:origin: nileshpambhar/MultiPhotoPicker

public static DisplayMetrics getDisplayInfo(Activity activity) {
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindow().getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm;
  }
}

代码示例来源:origin: jraska/Falcon

@SuppressWarnings("deprecation") private Point getSize() {
 Point size = new Point();
 Display defaultDisplay = getWindow().getWindowManager().getDefaultDisplay();
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
  defaultDisplay.getSize(size);
 } else {
  size.x = defaultDisplay.getWidth();
  size.y = defaultDisplay.getHeight();
 }
 return size;
}

代码示例来源:origin: stkent/bugshaker-android

@NonNull
private static Bitmap getScreenSizedBitmap(@NonNull final Activity activity) {
  final Window window = ActivityUtils.getWindow(activity);
  final Display screen = window.getWindowManager().getDefaultDisplay();
  final Point screenSize = new Point();
  screen.getSize(screenSize);
  return Bitmap.createBitmap(screenSize.x, screenSize.y, Bitmap.Config.ARGB_8888);
}

代码示例来源:origin: panshen/PopupCircleMenu

public PopupLayer(Activity context, int radius) {
  super(context);
  mRadius = radius;
  mContext = context;
  Display display = context.getWindow().getWindowManager().getDefaultDisplay();
  mRectWindowRange = new Rect();
  btTempRect = new Rect();
  display.getRectSize(mRectWindowRange);
  mWindowCenterPoint = new Point(mRectWindowRange.centerX(), mRectWindowRange.centerY());
  mShadowView = new View(context);
  mShadowView.setBackgroundColor(Color.parseColor("#66000000"));
  mShadowView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
  addView(mShadowView);
}

代码示例来源:origin: fccaikai/AppUpdate

private int calcWidth() {
  if (getResources().getBoolean(R.bool.au_is_tablet)) {
    return getResources().getDimensionPixelSize(R.dimen.au_dialog_max_width);
  } else {
    WindowManager wm = getWindow().getWindowManager();
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    final int windowWidth = size.x;
    final int windowHorizontalPadding = getResources().getDimensionPixelSize(R.dimen.au_dialog_horizontal_margin);
    return windowWidth - (windowHorizontalPadding * 2);
  }
}

代码示例来源:origin: Hu12037102/ImageCompress

private void init() {
  Window window = getWindow();
  if (window == null) {
    dismiss();
    return;
  }
  WindowManager.LayoutParams layoutParams = window.getAttributes();
  WindowManager windowManager = getWindow().getWindowManager();
  DisplayMetrics dm = new DisplayMetrics();
  windowManager.getDefaultDisplay().getMetrics(dm);
  layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
  layoutParams.width = dm.widthPixels;
  layoutParams.gravity = Gravity.BOTTOM;
  window.setAttributes(layoutParams);
  window.setWindowAnimations(R.style.DialogAnimation);
}

代码示例来源:origin: 296777513/pedometer

private void initTabline() {
  imageView = (ImageView) view.findViewById(R.id.pk_tabline);
  Display display = getActivity().getWindow().getWindowManager()
      .getDefaultDisplay();
  DisplayMetrics outMetrics = new DisplayMetrics();
  display.getMetrics(outMetrics);// 得到屏幕的像素和分辨率,得到了屏幕的高度和宽度
  mScreen1_2 = outMetrics.widthPixels / 2
      - DisplayUtil.dip2px(getActivity(), 60);
  LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) imageView
      .getLayoutParams();
  lp.leftMargin = DisplayUtil.dip2px(getActivity(), 60);
  lp.width = mScreen1_2;
  imageView.setLayoutParams(lp);
}

代码示例来源:origin: mabeijianxi/ViewLargerImageUtil

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
  super.onCreate(bundle);
  getWindow().setGravity(Gravity.BOTTOM);
  WindowManager m = getWindow().getWindowManager();
  Display d = m.getDefaultDisplay();
  WindowManager.LayoutParams p = getWindow().getAttributes();
  p.width = d.getWidth();
  getWindow().setAttributes(p);
}

代码示例来源:origin: samlss/TimoMenu

private void initMenu(){
  int itemViewWidth = (getWindow().getWindowManager().getDefaultDisplay().getWidth() - 40) / 5;
  mTimoMenu =  new TimoMenu.Builder(this)
      .setGravity(Gravity.CENTER)
      .setMenuMargin(new Rect(20, 20, 20, 20))
      .setMenuPadding(new Rect(0, 10, 0, 10))
      .addRow(null, MenuHelper.getTopList(itemViewWidth))
      .addRow(null, MenuHelper.getBottomList(itemViewWidth))
      .build();
}

代码示例来源:origin: derry/delion

@Override
public void onAttachedToWindow() {
  super.onAttachedToWindow();
  // See enableHardwareAcceleration()
  if (mSetWindowHWA) {
    mSetWindowHWA = false;
    getWindow().setWindowManager(
        getWindow().getWindowManager(),
        getWindow().getAttributes().token,
        getComponentName().flattenToString(),
        true /* hardwareAccelerated */);
  }
}

相关文章

Window类方法