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

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

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

Window.getDecorView介绍

暂无

代码示例

代码示例来源:origin: scwang90/SmartRefreshLayout

/** android 6.0设置字体颜色 */
  @RequiresApi(Build.VERSION_CODES.M)
  private static void darkModeForM(Window window, boolean dark) {
//        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//        window.setStatusBarColor(Color.TRANSPARENT);

    int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
    if (dark) {
      systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    } else {
      systemUiVisibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
    }
    window.getDecorView().setSystemUiVisibility(systemUiVisibility);
  }

代码示例来源:origin: JakeWharton/butterknife

/**
 * BindView annotated fields and methods in the specified {@code target} using the {@code source}
 * {@link Activity} as the view root.
 *
 * @param target Target class for view binding.
 * @param source Activity on which IDs will be looked up.
 */
@NonNull @UiThread
public static Unbinder bind(@NonNull Object target, @NonNull Activity source) {
 View sourceView = source.getWindow().getDecorView();
 return bind(target, sourceView);
}

代码示例来源:origin: JakeWharton/butterknife

/**
 * BindView annotated fields and methods in the specified {@link Activity}. The current content
 * view is used as the view root.
 *
 * @param target Target activity for view binding.
 */
@NonNull @UiThread
public static Unbinder bind(@NonNull Activity target) {
 View sourceView = target.getWindow().getDecorView();
 return bind(target, sourceView);
}

代码示例来源:origin: JakeWharton/butterknife

/**
 * BindView annotated fields and methods in the specified {@link Activity}. The current content
 * view is used as the view root.
 *
 * @param target Target activity for view binding.
 */
@NonNull @UiThread
public static Unbinder bind(@NonNull Activity target) {
 View sourceView = target.getWindow().getDecorView();
 return bind(target, sourceView);
}

代码示例来源:origin: JakeWharton/butterknife

/**
 * BindView annotated fields and methods in the specified {@link Dialog}. The current content
 * view is used as the view root.
 *
 * @param target Target dialog for view binding.
 */
@NonNull @UiThread
public static Unbinder bind(@NonNull Dialog target) {
 View sourceView = target.getWindow().getDecorView();
 return bind(target, sourceView);
}

代码示例来源:origin: JakeWharton/butterknife

/**
 * BindView annotated fields and methods in the specified {@link Dialog}. The current content
 * view is used as the view root.
 *
 * @param target Target dialog for view binding.
 */
@NonNull @UiThread
public static Unbinder bind(@NonNull Dialog target) {
 View sourceView = target.getWindow().getDecorView();
 return bind(target, sourceView);
}

代码示例来源:origin: JakeWharton/butterknife

/**
 * BindView annotated fields and methods in the specified {@code target} using the {@code source}
 * {@link Dialog} as the view root.
 *
 * @param target Target class for view binding.
 * @param source Dialog on which IDs will be looked up.
 */
@NonNull @UiThread
public static Unbinder bind(@NonNull Object target, @NonNull Dialog source) {
 View sourceView = source.getWindow().getDecorView();
 return bind(target, sourceView);
}

代码示例来源:origin: JakeWharton/butterknife

/**
 * BindView annotated fields and methods in the specified {@code target} using the {@code source}
 * {@link Activity} as the view root.
 *
 * @param target Target class for view binding.
 * @param source Activity on which IDs will be looked up.
 */
@NonNull @UiThread
public static Unbinder bind(@NonNull Object target, @NonNull Activity source) {
 View sourceView = source.getWindow().getDecorView();
 return bind(target, sourceView);
}

代码示例来源:origin: JakeWharton/butterknife

/**
 * BindView annotated fields and methods in the specified {@code target} using the {@code source}
 * {@link Dialog} as the view root.
 *
 * @param target Target class for view binding.
 * @param source Dialog on which IDs will be looked up.
 */
@NonNull @UiThread
public static Unbinder bind(@NonNull Object target, @NonNull Dialog source) {
 View sourceView = source.getWindow().getDecorView();
 return bind(target, sourceView);
}

代码示例来源:origin: androidannotations/androidannotations

/**
 * Invoke this method to unregister a view hierarchy.
 * 
 * @param activity
 *            The activity whose view hierarchy/window to unregister
 * 
 * @see #addWindow(Activity)
 * @see #removeWindow(View)
 */
public void removeWindow(Activity activity) {
  removeWindow(activity.getWindow().getDecorView());
}

代码示例来源:origin: androidannotations/androidannotations

/**
 * Invoke this method to change the currently focused window.
 * 
 * @param activity
 *            The activity whose view hierarchy/window hasfocus, or null to
 *            remove focus
 */
public void setFocusedWindow(Activity activity) {
  setFocusedWindow(activity.getWindow().getDecorView());
}

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

Rect rectangle = new Rect();
Window window = getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
int statusBarHeight = rectangle.top;
int contentViewTop = 
  window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight= contentViewTop - statusBarHeight;

  Log.i("*** Elenasys :: ", "StatusBar Height= " + statusBarHeight + " , TitleBar Height = " + titleBarHeight);

代码示例来源:origin: libgdx/libgdx

protected void hideStatusBar (AndroidApplicationConfiguration config) {
  if (!config.hideStatusBar || getVersion() < 11) return;
  View rootView = getWindow().getDecorView();
  try {
    Method m = View.class.getMethod("setSystemUiVisibility", int.class);
    m.invoke(rootView, 0x0);
    m.invoke(rootView, 0x1);
  } catch (Exception e) {
    log("AndroidApplication", "Can't hide status bar", e);
  }
}

代码示例来源:origin: libgdx/libgdx

protected void hideStatusBar (AndroidApplicationConfiguration config) {
  if (!config.hideStatusBar || getVersion() < 11) return;
  View rootView = getWindow().getDecorView();
  try {
    Method m = View.class.getMethod("setSystemUiVisibility", int.class);
    m.invoke(rootView, 0x0);
    m.invoke(rootView, 0x1);
  } catch (Exception e) {
    log("AndroidApplication", "Can't hide status bar", e);
  }
}

代码示例来源:origin: libgdx/libgdx

@TargetApi(19)
@Override
public void useImmersiveMode (boolean use) {
  if (!use || getVersion() < Build.VERSION_CODES.KITKAT) return;
  View view = getWindow().getDecorView();
  try {
    Method m = View.class.getMethod("setSystemUiVisibility", int.class);
    int code = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
      | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN
      | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    m.invoke(view, code);
  } catch (Exception e) {
    log("AndroidApplication", "Can't set immersive mode", e);
  }
}

代码示例来源:origin: libgdx/libgdx

@TargetApi(19)
@Override
public void useImmersiveMode (boolean use) {
  if (!use || getVersion() < Build.VERSION_CODES.KITKAT) return;
  View view = getWindow().getDecorView();
  try {
    Method m = View.class.getMethod("setSystemUiVisibility", int.class);
    int code = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
      | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN
      | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    m.invoke(view, code);
  } catch (Exception e) {
    log("AndroidApplication", "Can't set immersive mode", e);
  }
}

代码示例来源:origin: libgdx/libgdx

protected void hideStatusBar (boolean hide) {
  if (!hide || getVersion() < 11) return;
  View rootView = getWindow().getDecorView();
  try {
    Method m = View.class.getMethod("setSystemUiVisibility", int.class);
    if (getVersion() <= 13) m.invoke(rootView, 0x0);
    m.invoke(rootView, 0x1);
  } catch (Exception e) {
    log("AndroidApplication", "Can't hide status bar", e);
  }
}

代码示例来源:origin: libgdx/libgdx

protected void hideStatusBar (boolean hide) {
  if (!hide || getVersion() < 11) return;
  View rootView = getWindow().getDecorView();
  try {
    Method m = View.class.getMethod("setSystemUiVisibility", int.class);
    if (getVersion() <= 13) m.invoke(rootView, 0x0);
    m.invoke(rootView, 0x1);
  } catch (Exception e) {
    log("AndroidApplication", "Can't hide status bar", e);
  }
}

代码示例来源:origin: libgdx/libgdx

public void createListener (final AndroidApplicationBase application) {
    try {
      View rootView = application.getApplicationWindow().getDecorView();
      rootView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange (int arg0) {
          application.getHandler().post(new Runnable() {
            @Override
            public void run () {
              application.useImmersiveMode(true);
            }
          });
        }
      });
    } catch (Throwable t) {
      application.log("AndroidApplication", "Can't create OnSystemUiVisibilityChangeListener, unable to use immersive mode.", t);
    }
  }
}

代码示例来源:origin: libgdx/libgdx

public void createListener (final AndroidApplicationBase application) {
    try {
      View rootView = application.getApplicationWindow().getDecorView();
      rootView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange (int arg0) {
          application.getHandler().post(new Runnable() {
            @Override
            public void run () {
              application.useImmersiveMode(true);
            }
          });
        }
      });
    } catch (Throwable t) {
      application.log("AndroidApplication", "Can't create OnSystemUiVisibilityChangeListener, unable to use immersive mode.", t);
    }
  }
}

相关文章

微信公众号

最新文章

更多

Window类方法