android.view.Window类的使用及代码示例

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

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

Window介绍

暂无

代码示例

代码示例来源:origin: cymcsg/UltimateAndroid

/**
 * Get height of status bar
 * @param activity
 * @return
 */
public static int getStatusBarHeight(Activity activity) {
  Rect frame = new Rect();
  activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
  return frame.top;
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

/**
 * android 6.0设置字体颜色
 */
@TargetApi(Build.VERSION_CODES.M)
public static void setStatusBarDarkModeForM(Window window) {
  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();
  systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
  window.getDecorView().setSystemUiVisibility(systemUiVisibility);
}

代码示例来源:origin: JessYanCoding/MVPArms

public static void setFullScreen(Activity activity) {
  WindowManager.LayoutParams params = activity.getWindow()
      .getAttributes();
  params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
  activity.getWindow().setAttributes(params);
  activity.getWindow().addFlags(
      WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

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

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  Window window = getWindow();
  window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
  window.setStatusBarColor(Color.BLUE);
}

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

Window window = activity.getWindow();

// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

// finally change the color
window.setStatusBarColor(activity.getResources().getColor(R.color.my_statusbar_color));

代码示例来源: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: robolectric/robolectric

private void init() {
 LocalActivityManager lam = new LocalActivityManager((Activity) getContext(), true);
 lam.dispatchCreate(null);
 final Window window = lam.startActivity("foo", new Intent(getContext(), InnerActivity.class));
 // Add the decorView's child to this LinearLayout's children.
 final View innerContents = window.getDecorView().findViewById(R.id.lam_inner_contents);
 ((ViewGroup) innerContents.getParent()).removeView(innerContents);
 addView(innerContents);
}

代码示例来源: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: huburt-Hu/NewbieGuide

Context context = child.getContext();
if (context instanceof Activity) {
  decorView = ((Activity) context).getWindow().getDecorView();
Rect result = new Rect();
Rect tmpRect = new Rect();
  child.getHitRect(result);
  return result;
  tmp.getHitRect(tmpRect);
  LogUtil.i("tmp hit Rect:" + tmpRect);
  if (!tmp.getClass().equals(FRAGMENT_CON)) {

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

LocalActivityManager mgr = getLocalActivityManager();

Intent i = new Intent(this, SomeActivity.class);

Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;

if(wd != null) {
  mSomeContainer.addView(wd);
}

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
protected void onCreate(Bundle savedInstanceState) {
  // Service
  Intent i = new Intent();
  i.setClass(this, DownloadManagerService.class);
  startService(i);
  ThemeHelper.setTheme(this);
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_downloader);
  Toolbar toolbar = findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  ActionBar actionBar = getSupportActionBar();
  if (actionBar != null) {
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(R.string.downloads_title);
    actionBar.setDisplayShowTitleEnabled(true);
  }
  getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
      updateFragments();
      getWindow().getDecorView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
    }
  });
}

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

class MyActivityGroup extends ActivityGroup {
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  startChildActivity("first", new Intent(this, First.class));
 }
 public void startChildActivity(Intent intent) {
  Window window = getLocalActivityManager().startActivity(id, intent);
   if (window != null) {
    setContentView(window.getDecorView());
  }
 }
}

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

Activity activity = ...;
AlertDialog dialog = ...;

// retrieve display dimensions
Rect displayRectangle = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);

// inflate and adjust layout
LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.your_dialog_layout, null);
layout.setMinimumWidth((int)(displayRectangle.width() * 0.9f));
layout.setMinimumHeight((int)(displayRectangle.height() * 0.9f));

dialog.setView(layout);

代码示例来源:origin: aa112901/remusic

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  if (getIntent().getExtras() != null) {
    albumId = getIntent().getStringExtra("albumid");
    albumPath = getIntent().getStringExtra("albumart");
    albumName = getIntent().getStringExtra("albumname");
    albumDes = getIntent().getStringExtra("albumdetail");
    artistName = getIntent().getStringExtra("artistname");
  }
  setContentView(R.layout.activity_playlist);
  loadFrameLayout = (FrameLayout) findViewById(R.id.state_container);
  headerViewContent = (FrameLayout) findViewById(R.id.headerview);
  headerDetail = (RelativeLayout) findViewById(R.id.headerdetail);
  toolbar = (Toolbar) findViewById(R.id.toolbar);
  mHandler = HandlerUtil.getInstance(this);
  mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
  mActionBarSize = CommonUtils.getActionBarHeight(this);
  mStatusSize = CommonUtils.getStatusHeight(this);
  tryAgain = (TextView) findViewById(R.id.try_again);
  setUpEverything();
}

代码示例来源:origin: ankidroid/Anki-Android

/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.video_player);
  mPath = getIntent().getStringExtra("path");
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);        
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  mVideoView = (VideoView) findViewById(R.id.video_surface);
  mVideoView.getHolder().addCallback(this);
  mSoundPlayer = new Sound();
}
@Override

代码示例来源: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: robolectric/robolectric

@Test
public void decorViewSizeEqualToDisplaySize() {
 Activity activity = buildActivity(Activity.class).create().visible().get();
 View decorView = activity.getWindow().getDecorView();
 assertThat(decorView).isNotEqualTo(null);
 ViewRootImpl root = decorView.getViewRootImpl();
 assertThat(root).isNotEqualTo(null);
 assertThat(decorView.getWidth()).isNotEqualTo(0);
 assertThat(decorView.getHeight()).isNotEqualTo(0);
 Display display = ShadowDisplay.getDefaultDisplay();
 assertThat(decorView.getWidth()).isEqualTo(display.getWidth());
 assertThat(decorView.getHeight()).isEqualTo(display.getHeight());
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
   * 获取当前屏幕截图,不包含状态栏(这个方法没测试通过)
   * 
   * @param activity
   * @return Bitmap
   */
  public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;

    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height
        - statusBarHeight);
    view.destroyDrawingCache();
    return bp;
  }
}

代码示例来源:origin: wangdan/AisenWeiBo

private void showEmotionView(boolean showAnimation) {
    if (showAnimation) {
      transitioner.setDuration(200);
    } else {
      transitioner.setDuration(0);
    }

    int statusBarHeight = SystemUtils.getStatusBarHeight(getActivity());
    emotionHeight = SystemUtils.getKeyboardHeight(getActivity());

    SystemUtils.hideSoftInput(getActivity(), editContent);
    layEmotion.getLayoutParams().height = emotionHeight;
    layEmotion.setVisibility(View.VISIBLE);
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // 2015 05-09 在5.0有navigationbar的手机,高度高了一个statusBar
    int lockHeight = SystemUtils.getAppContentHeight(getActivity());
//        if (Build.VERSION.SDK_INT < 19)
//            lockHeight = lockHeight - statusBarHeight;
    lockContainerHeight(lockHeight);
  }

代码示例来源:origin: aa112901/remusic

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  if (getIntent().getExtras() != null) {
    isLocalPlaylist = false;
    mBillType = getIntent().getIntExtra("type", -1);
    albumPath = getIntent().getIntExtra("pic", 0);
    playlistName = getIntent().getStringExtra("playlistname");
    playlistDetail = getIntent().getStringExtra("playlistDetail");
  }
  mContext = this;
  setContentView(R.layout.activity_rank_playlist);
  loadFrameLayout = (FrameLayout) findViewById(R.id.state_container);
  headerViewContent = (FrameLayout) findViewById(R.id.headerview);
  headerDetail = (RelativeLayout) findViewById(R.id.headerdetail);
  toolbar = (Toolbar) findViewById(R.id.toolbar);
  mHandler = HandlerUtil.getInstance(this);
  mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
  mActionBarSize = CommonUtils.getActionBarHeight(this);
  mStatusSize = CommonUtils.getStatusHeight(this);
  tryAgain = (TextView) findViewById(R.id.try_again);
  setUpEverything();
}

相关文章

微信公众号

最新文章

更多

Window类方法