Java Code Examples for android.view.Window#getAttributes()
The following examples show how to use
android.view.Window#getAttributes() .
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: VMTheme.java From VMLibrary with Apache License 2.0 | 6 votes |
/** * 针对魅族系统设置状态栏图标为深色和魅族特定的文字风格 * * @param window 需要设置的窗口 * @param dark 是否把状态栏文字及图标颜色设置为深色 * @return 成功执行返回 true */ public static boolean statusBarDarkModeFromFlyme(Window window, boolean dark) { boolean result = false; if (window != null) { try { WindowManager.LayoutParams lp = window.getAttributes(); Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); Field mzFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags"); darkFlag.setAccessible(true); mzFlags.setAccessible(true); int bit = darkFlag.getInt(null); int value = mzFlags.getInt(lp); if (dark) { value |= bit; } else { value &= ~bit; } mzFlags.setInt(lp, value); window.setAttributes(lp); result = true; } catch (Exception e) { } } return result; }
Example 2
Source File: EmotionKeyboard.java From timecat with Apache License 2.0 | 6 votes |
/** * 锁定内容高度,防止跳闪 */ private void lockContentHeight() { mActivity.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); mContentView.setY(mContentView.getY()); //窗口对齐屏幕宽度 Window win = mActivity.getWindow(); win.getDecorView().setPadding(0, 0, 0, 0); WindowManager.LayoutParams lp = win.getAttributes(); lp.gravity = Gravity.TOP;//设置对话框置顶显示 lp.y = ScreenUtil.getScreenHeight(mActivity) - keyBoardHeight - mContentView.getHeight() - ScreenUtil.getStateBarHeight(mActivity);//底部偏离量=lp.y win.setAttributes(lp); }
Example 3
Source File: Glass.java From Glass with MIT License | 6 votes |
public Builder statusBar(Window window) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Context context = window.getContext().getApplicationContext(); LocalDisplay.init(context); WindowManager.LayoutParams localLayoutParams = window.getAttributes(); localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags); ViewGroup contentView = (ViewGroup)window.getDecorView().findViewById(android.R.id.content); View mStatusBarView = new View(context); int height = LocalDisplay.getStatusHeight(context.getResources()); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, height); params.gravity = Gravity.TOP; mStatusBarView.setLayoutParams(params); contentView.addView(mStatusBarView); background(mStatusBarView); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Setter windowSetter = SetterFactory.getSystemSetter(window); add(windowSetter); } return this; }
Example 4
Source File: ActionSheet4WeChat.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
/** * * @Title showSheet * @param activity * 上下文环境 * @param actionSheetConfig * ActionSheet配置项 * @param actionSheetItemSelected * ActionSheet Item选中监听 * @param cancelListener * 取消按钮的监听,无需监听可传null * @return Dialog 返回类型 */ @SuppressLint("NewApi") public Dialog show(final Activity activity, ActionSheetConfig actionSheetConfig, final OnActionSheetItemSelected actionSheetItemSelected, OnCancelListener cancelListener) { final Dialog dlg = new Dialog(activity, R.style.ActionSheet); LinearLayout layout = this.getLayout(activity, dlg, actionSheetConfig, actionSheetItemSelected); TextView mCancel = (TextView) layout.findViewById(R.id.cancel); mCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { actionSheetItemSelected.onActionSheetItemSelected(activity, 0); dlg.dismiss(); } }); Window w = dlg.getWindow(); WindowManager.LayoutParams lp = w.getAttributes(); lp.x = 0; final int cMakeBottom = -1000; lp.y = cMakeBottom; lp.gravity = Gravity.BOTTOM; dlg.onWindowAttributesChanged(lp); dlg.setCanceledOnTouchOutside(false); if (cancelListener != null) dlg.setOnCancelListener(cancelListener); dlg.setContentView(layout); dlg.show(); // 设置点击弹窗外部取消actionsheet dlg.setCanceledOnTouchOutside(true); return dlg; }
Example 5
Source File: UpdateDialog.java From AppUpdate with Apache License 2.0 | 5 votes |
private void setWindowSize(Context context) { Window dialogWindow = this.getWindow(); WindowManager.LayoutParams lp = dialogWindow.getAttributes(); lp.width = (int) (ScreenUtil.getWith(context) * 0.7f); lp.height = WindowManager.LayoutParams.WRAP_CONTENT; lp.gravity = Gravity.CENTER; dialogWindow.setAttributes(lp); }
Example 6
Source File: StatusBarUtil.java From imsdk-android with MIT License | 5 votes |
/** * 设置状态栏图标为深色和魅族特定的文字风格 * 可以用来判断是否为Flyme用户 * * @param window 需要设置的窗口 * @param dark 是否把状态栏字体及图标颜色设置为深色 * @return boolean 成功执行返回true */ public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) { boolean result = false; if (window != null) { try { WindowManager.LayoutParams lp = window.getAttributes(); Field darkFlag = WindowManager.LayoutParams.class .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); Field meizuFlags = WindowManager.LayoutParams.class .getDeclaredField("meizuFlags"); darkFlag.setAccessible(true); meizuFlags.setAccessible(true); int bit = darkFlag.getInt(null); int value = meizuFlags.getInt(lp); if (dark) { value |= bit; } else { value &= ~bit; } meizuFlags.setInt(lp, value); window.setAttributes(lp); result = true; } catch (Exception e) { return false; } } return result; }
Example 7
Source File: BaseDialog.java From AndroidProject with Apache License 2.0 | 5 votes |
/** * 获取 Dialog 的动画 */ public int getWindowAnimations() { Window window = getWindow(); if (window != null) { return window.getAttributes().windowAnimations; } return AnimAction.NO_ANIM; }
Example 8
Source File: BrightnessUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
/** * 获取窗口亮度 * * @param window 窗口 * @return 屏幕亮度 0-255 */ public static int getWindowBrightness(final Window window) { WindowManager.LayoutParams lp = window.getAttributes(); float brightness = lp.screenBrightness; if (brightness < 0) return getBrightness(); return (int) (brightness * 255); }
Example 9
Source File: ActionDialog.java From umeng_community_android with MIT License | 5 votes |
private void initDialog() { this.setContentView(ResFinder.getLayout("umeng_comm_more_dialog_layout")); this.setCanceledOnTouchOutside(true); Window window = this.getWindow(); window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); WindowManager.LayoutParams wlp = window.getAttributes(); wlp.gravity = Gravity.BOTTOM; window.setAttributes(wlp); }
Example 10
Source File: ScreenUtil.java From timecat with Apache License 2.0 | 5 votes |
public static void setWindowFlag(Activity activity, final int bits, boolean on) { Window win = activity.getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
Example 11
Source File: MainActivity.java From quickmark with MIT License | 5 votes |
@TargetApi(19) private void setTranslucentStatus(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
Example 12
Source File: BaseActivity.java From TLint with Apache License 2.0 | 5 votes |
/** * set status bar translucency */ protected void setTranslucentStatus(boolean on) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); } }
Example 13
Source File: LoadingOverlay.java From android-skeleton-project with MIT License | 5 votes |
@Override public void onResume() { super.onResume(); Window window = getDialog().getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.width = WindowManager.LayoutParams.MATCH_PARENT; window.setAttributes(lp); }
Example 14
Source File: Dialog.java From MDPreference with Apache License 2.0 | 5 votes |
/** * Set the dim amount of the region outside this Dialog. * * @param amount The dim amount in [0..1]. * @return The Dialog for chaining methods. */ public Dialog dimAmount(float amount) { Window window = getWindow(); if (amount > 0f) { window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); WindowManager.LayoutParams lp = window.getAttributes(); lp.dimAmount = amount; window.setAttributes(lp); } else window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); return this; }
Example 15
Source File: SystemBarTintManager.java From LLApp 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) @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: Tool.java From DialogUtil with Apache License 2.0 | 4 votes |
public static void adjustWH( Dialog dialog, ConfigBean bean ) { if (dialog == null){ return; } Window window = dialog.getWindow(); 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 = 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.forceWidthPercent >0 && bean.forceWidthPercent <=1.0f){ widthRatio = bean.forceWidthPercent; } if(measuredHeight > bean.maxHeightPercent * height){ heightRatio = bean.maxHeightPercent; } if(bean.forceHeightPercent >0 && bean.forceHeightPercent <=1.0f){ heightRatio = bean.forceHeightPercent; } if(istheTypeOfNotAdjust(bean)){ /*wl.width = ViewGroup.LayoutParams.WRAP_CONTENT; wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;*/ }else { // rootView.setPadding(0,30,0,30); 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; } // } } dialog.onWindowAttributesChanged(wl); }
Example 17
Source File: BottomMenu.java From android-project-wo2b with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") public void showBottomView(boolean onTouchOutsideable) { if (this.mTheme == 0) { this.dialog = new Dialog(mContext); } else { this.dialog = new Dialog(mContext, mTheme); } this.dialog.setCanceledOnTouchOutside(onTouchOutsideable); this.dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); this.dialog.setContentView(this.mContentView); this.mContentView.setFocusable(true); this.mContentView.setFocusableInTouchMode(true); this.mContentView.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_DOWN && dialog.isShowing()) { dialog.dismiss(); return true; } return false; } }); Window wm = this.dialog.getWindow(); WindowManager m = wm.getWindowManager(); Display d = m.getDefaultDisplay(); WindowManager.LayoutParams p = wm.getAttributes(); p.width = (d.getWidth() * 1); if (this.isTop) { p.gravity = Gravity.TOP; } else { p.gravity = Gravity.BOTTOM; } if (this.animationStyle != 0) { wm.setWindowAnimations(this.animationStyle); } wm.setAttributes(p); this.dialog.show(); }
Example 18
Source File: BaseDialog.java From AndroidProject with Apache License 2.0 | 4 votes |
/** * 创建 */ @SuppressLint("RtlHardcoded") public BaseDialog create() { // 判断布局是否为空 if (mContentView == null) { throw new IllegalArgumentException("are you ok?"); } // 如果当前没有设置重心,就设置一个默认的重心 if (mGravity == Gravity.NO_GRAVITY) { mGravity = Gravity.CENTER; } // 如果当前没有设置动画效果,就设置一个默认的动画效果 if (mAnimations == AnimAction.NO_ANIM) { switch (mGravity) { case Gravity.TOP: mAnimations = AnimAction.TOP; break; case Gravity.BOTTOM: mAnimations = AnimAction.BOTTOM; break; case Gravity.LEFT: mAnimations = AnimAction.LEFT; break; case Gravity.RIGHT: mAnimations = AnimAction.RIGHT; break; default: mAnimations = AnimAction.DEFAULT; break; } } mDialog = createDialog(mContext, mThemeId); mDialog.setContentView(mContentView); mDialog.setCancelable(mCancelable); if (mCancelable) { mDialog.setCanceledOnTouchOutside(mCanceledOnTouchOutside); } // 设置参数 Window window = mDialog.getWindow(); if (window != null) { WindowManager.LayoutParams params = window.getAttributes(); params.width = mWidth; params.height = mHeight; params.gravity = mGravity; params.windowAnimations = mAnimations; window.setAttributes(params); if (mBackgroundDimEnabled) { window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); window.setDimAmount(mBackgroundDimAmount); } else { window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); } } if (mOnShowListeners != null) { mDialog.setOnShowListeners(mOnShowListeners); } if (mOnCancelListeners != null) { mDialog.setOnCancelListeners(mOnCancelListeners); } if (mOnDismissListeners != null) { mDialog.setOnDismissListeners(mOnDismissListeners); } if (mOnKeyListener != null) { mDialog.setOnKeyListener(mOnKeyListener); } for (int i = 0; mClickArray != null && i < mClickArray.size(); i++) { mContentView.findViewById(mClickArray.keyAt(i)).setOnClickListener(new ViewClickWrapper(mDialog, mClickArray.valueAt(i))); } Activity activity = getActivity(); if (activity != null) { DialogLifecycle.with(activity, mDialog); } return mDialog; }
Example 19
Source File: checkBoxDialog.java From sealrtc-android with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view = View.inflate(mContext, R.layout.layout_app_dialog_checkbox, null); // LinearLayout.LayoutParams params=new // LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, // LinearLayout.LayoutParams.WRAP_CONTENT); // params.setMargins(0,0,40,0); // view.setLayoutParams(params); setContentView(view); // this.setCanceledOnTouchOutside(false); // this.setCancelable(false); // Window win = getWindow(); WindowManager.LayoutParams lp = win.getAttributes(); // lp.type = WindowManager.LayoutParams.TYPE_TOAST; lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; lp.gravity = Gravity.RIGHT; lp.x = 75; // px 对话框出现在右边,所以lp.x就表示相对右边的偏移,负值忽略. win.setAttributes(lp); setCanceledOnTouchOutside(false); setCancelable(false); btn_modeSelect = (AppCompatCheckBox) findViewById(R.id.btn_modeSelect); btnRaiseHand = (AppCompatCheckBox) findViewById(R.id.menu_request_to_normal); btnSwitchCamera = (AppCompatCheckBox) findViewById(R.id.menu_switch); // btnMuteMic = (AppCompatCheckBox) findViewById(R.id.menu_mute_mic); btnMuteSpeaker = (AppCompatCheckBox) findViewById(R.id.menu_mute_speaker); btnWhiteBoard = (AppCompatCheckBox) findViewById(R.id.menu_whiteboard); btnChangeResolution_up = (AppCompatCheckBox) findViewById(R.id.menu_up); btnChangeResolution_down = (AppCompatCheckBox) findViewById(R.id.menu_down); btnChangeResolution_up.setVisibility(View.GONE); btnChangeResolution_down.setVisibility(View.GONE); }
Example 20
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);*/ }