Android--WindowManager(1),看完老板就给加薪了

本文详细介绍了如何在Android中使用Windowflag系列和softInputMode系列对窗口进行全屏、调整软键盘显示以及设置窗口类型,为Android开发者提供窗口控制的核心知识。
摘要由CSDN通过智能技术生成

Window flag系列

该系列主要用于对Window的flag进行设置。设置Window的flag,可以直接对Window的getAttributes()得到其 WindowManager.LayoutParams对象,然后直接对它flag变量操作。也可以Window的addFlags(int flags)方法,setFlags(int flags, int mask)方法,clearFlags(int flags)方法进行操作。

比如设置全屏

Window window = getWindow();

WindowManager.LayoutParams winParams = win.getAttributes();

winParams.flags=winParams.flags|WindowManager.LayoutParams.FLAG_FULLSCREEN ;

window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

取消全屏

Window window = getWindow();

winParams.flags=winParams.flags&~WindowManager.LayoutParams.FLAG_FULLSCREEN;

window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

window.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);

所有Window flag如下:

intFLAGS_CHANGED用于表示flags发生了变化,关于此的详细内容请看后文。
intFLAG_ALLOW_LOCK_WHILE_SCREEN_ONWindow flag: as long as this window is visible to the user, allow the lock screen to activate while the screen is on.
当该window对用户可见的时候,允许锁屏。
intFLAG_ALT_FOCUSABLE_IMWindow flag: invert the state of FLAG_NOT_FOCUSABLE with respect to how this window interacts with the current method.
intFLAG_BLUR_BEHINDWindow flag: blur everything behind this window.
让该window后所有东西都模糊(blur)
intFLAG_DIM_BEHINDWindow flag: everything behind this window will be dimmed.
让该window后所有的东西都成暗淡(dim)
intFLAG_DISMISS_KEYGUARDWindow flag: when set the window will cause the keyguard to be dismissed, 
only if it is not a secure lock keyguard.
intFLAG_DITHERWindow flag: turn on dithering when compositing this window to the screen.
开启抖动(dithering)
intFLAG_FORCE_NOT_FULLSCREENWindow flag: Override {@link #FLAG_FULLSCREEN and force the screen decorations (such as status bar) to be shown.
恢复window非全屏显示
intFLAG_FULLSCREENWindow flag: Hide all screen decorations (e.g.
让window进行全屏显示
intFLAG_HARDWARE_ACCELERATED

Indicates whether this window should be hardware accelerated.

对该window进行硬件加速.

该flag必须在设置你的Activity或Dialog的Content View之前进行设置,

而且如果你在mainfest文件中用android:hardwareAccelerated开启了该属性的话,那么你在程序中就不能再改变它。mainfest文件中android:hardwareAccelerated属性默认是开启的("true")。

intFLAG_IGNORE_CHEEK_PRESSESWindow flag: intended for windows that will often be used when the user is holding the screen against their face, it will aggressively filter the event stream to prevent unintended presses in this situation that may not be desired for a particular window, when such an event stream is detected, the application will receive a CANCEL motion event to indicate this so applications can handle this accordingly by taking no action on the event until the finger is released.
intFLAG_KEEP_SCREEN_ONWindow flag: as long as this window is visible to the user, keep the device's screen turned on and bright.
当该window对用户可见时,让设备屏幕处于高亮(bright)状态。
intFLAG_LAYOUT_INSET_DECORWindow flag: a special option only for use in combination with FLAG_LAYOUT_IN_SCREEN.
intFLAG_LAYOUT_IN_SCREENWindow flag: place the window within the entire screen, ignoring decorations around the border (a.k.a.
让window占满整个手机屏幕,不留任何边界(border)
intFLAG_LAYOUT_NO_LIMITSWindow flag: allow window to extend outside of the screen.
window大小不再不受手机屏幕大小限制,即window可能超出屏幕之外,这时部分内容在屏幕之外。
intFLAG_NOT_FOCUSABLEWindow flag: this window won't ever get key input focus, so the user can not send key or other button events to it.
让window不能获得焦点,这样用户快就不能向该window发送按键事件及按钮事件
intFLAG_NOT_TOUCHABLEWindow flag: this window can never receive touch events.
让该window不接受触摸屏事件
intFLAG_NOT_TOUCH_MODALWindow flag: Even when this window is focusable (its {@link #FLAG_NOT_FOCUSABLE is not set), 
allow any pointer events outside of the window to be sent to the windows behind it.
即使在该window在可获得焦点情况下,仍然把该window之外的任何event发送到该window之后的其他window.
intFLAG_SCALEDWindow flag: a special mode where the layout parameters are used to perform scaling of the surface when it is composited to the screen.
intFLAG_SECUREWindow flag: don't allow screen shots while this window is displayed.
当该window在进行显示的时候,不允许截屏。
intFLAG_SHOW_WALLPAPERWindow flag: ask that the system wallpaper be shown behind your window.
在该window后显示系统的墙纸(wallpaper)
intFLAG_SHOW_WHEN_LOCKEDWindow flag: special flag to let windows be shown when the screen is locked.
当锁屏的时候,显示该window.
intFLAG_SPLIT_TOUCHWindow flag: when set the window will accept for touch events outside of its bounds to be sent to other windows that also support split touch. When this flag is not set, the first pointer that goes down determines the window to which all subsequent touches go until all pointers go up. When this flag is set, each pointer (not necessarily the first) that goes down determines the window to which all subsequent touches of that pointer will go until that pointer goes up thereby enabling touches with multiple pointers to be split across multiple windows
当该window在可以接受触摸屏情况下,让因在该window之外,而发送到后面的window的触摸屏可以支持split touch.
intFLAG_TOUCHABLE_WHEN_WAKINGWindow flag: When set, if the device is asleep when the touch screen is pressed, you will receive this first touch event.
当手机处于睡眠状态时,如果屏幕被按下,那么该window将第一个收到到事件
intFLAG_TURN_SCREEN_ONWindow flag: when set as a window is being added or made visible, once the window has been shown then the system will poke the power manager's user activity (as if the user had woken up the device) to turn the screen on.
当然window被显示的时候,系统将把它当做一个用户活动事件,以点亮手机屏幕。
intFLAG_WATCH_OUTSIDE_TOUCHWindow flag: if you have set FLAG_NOT_TOUCH_MODAL, you can set this flag to receive a single special MotionEvent with the action MotionEvent.ACTION_OUTSIDE 
for touches that occur outside of your window.
如果你设置了该flag,那么在你FLAG_NOT_TOUNCH_MODAL的情况下,即使触摸屏事件发送在该window之外,其事件被发送到了后面的window,那么该window仍然将以MotionEvent.ACTION_OUTSIDE形式收到该触摸屏事件

softInputMode系列

该系列主要用于表示softInputMode,我们可以通过WindowManager.LayoutParams的softInputMode变量直接进行设置。 softInputMode只能是一个显示软键盘时的window调整方式bite与一个控制软键盘显示状态的bite的组合。

显示软键盘时的window调整方式可以是 SOFT_INPUT_ADJUST_NOTHING , SOFT_INPUT_ADJUST_PAN ,

SOFT_INPUT_ADJUST_RESIZE , SOFT_INPUT_ADJUST_UNSPECIFIED 之一。

用于描述软键盘显示的规则可以是 SOFT_INPUT_STATE_ALWAYS_HIDDEN , SOFT_INPUT_STATE_ALWAYS_VISIBLE ,

SOFT_INPUT_STATE_HIDDEN , SOFT_INPUT_STATE_VISIBLE , SOFT_INPUT_STATE_UNSPECIFIED 之一

关于softInputMode的更多知识请参考《 软件盘的开关

所有的softInputMode系列常量如下:

intSOFT_INPUT_ADJUST_NOTHINGAdjustment option for softInputMode: set to have a window not adjust for a shown input method.
当显示软键盘时,不调整window的布局
intSOFT_INPUT_ADJUST_PANAdjustment option for softInputMode: set to have a window pan when an input method is shown, so it doesn't need to deal with resizing but just panned by the framework to ensure the current input focus is visible.
当显示软键盘时,调整window的空白区域来显示软键盘。即使调整空白区域,软键盘还是有可能遮挡一些有内容区域,这时用户就只有退出软键盘才能看到这些被遮挡区域并进行交互。
intSOFT_INPUT_ADJUST_RESIZEAdjustment option for softInputMode: set to allow the window to be resized when an input method is shown, so that its contents are not covered by the input method.
当显示软键盘时,调整window内的控件大小以便显示软键盘。这样的话控件可能会变形。
intSOFT_INPUT_ADJUST_UNSPECIFIEDAdjustment option for softInputMode: nothing specified.
不指定显示软件盘时,window的调整方式。
intSOFT_INPUT_IS_FORWARD_NAVIGATIONBit for softInputMode: set when the user has navigated forward to the window.
表示用户导航(navigate)到了你的window
intSOFT_INPUT_MASK_ADJUSTMask for softInputMode of the bits that determine the way that the window should be adjusted to accommodate the soft input window.
显示软键盘时,用于表示window调整方式的bite的mask。
显示软键盘时的window调整方式可以是SOFT_INPUT_ADJUST_NOTHING,SOFT_INPUT_ADJUST_PAN,SOFT_INPUT_ADJUST_RESIZE,SOFT_INPUT_ADJUST_UNSPECIFIED。
用于描述软键盘显示的规则可以是SOFT_INPUT_STATE_ALWAYS_HIDDEN,SOFT_INPUT_STATE_ALWAYS_VISIBLE,
SOFT_INPUT_STATE_HIDDEN,SOFT_INPUT_STATE_VISIBLE,SOFT_INPUT_STATE_UNSPECIFIED之一
intSOFT_INPUT_MASK_STATEMask for softInputMode of the bits that determine the desired visibility state of the soft input area for this window.
用于描述软键盘显示规则的bite的mask.
intSOFT_INPUT_MODE_CHANGED用于表示softInputMode发生了变化。关于此的详细内容请看后文。
intSOFT_INPUT_STATE_ALWAYS_HIDDENVisibility state for softInputMode
please always hide any soft input area when this window receives focus.
总是隐藏软键盘。
intSOFT_INPUT_STATE_ALWAYS_VISIBLEVisibility state for softInputMode:
 please always make the soft input area visible when this window receives input focus.
总是显示软键盘
intSOFT_INPUT_STATE_HIDDENVisibility state for softInputMode
please hide any soft input area when normally appropriate (when the user is navigating forward to your window).
用户导航(navigate)到你的窗口的时候,隐藏软键盘
intSOFT_INPUT_STATE_UNCHANGEDVisibility state for softInputMode: please don't change the state of the soft input area.
intSOFT_INPUT_STATE_UNSPECIFIEDVisibility state for softInputMode: no state has been specified.
没有软键盘显示的约定规则
intSOFT_INPUT_STATE_VISIBLEVisibility state for softInputMode: please show the soft input area when normally appropriate 
(when the user is navigating forward to your window).
用户导航(navigate)到你的窗口的时候,显示软键盘

Window type系列

该系列主要用于表示 window 的类型。我们可以通过 WindowManager.LayoutParams 的 type 变量直接进行设置.

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

最后

现在都说互联网寒冬,其实无非就是你上错了车,且穿的少(技能),要是你上对车,自身技术能力够强,公司换掉的代价大,怎么可能会被裁掉,都是淘汰末端的业务Curd而已!现如今市场上初级程序员泛滥,这套教程针对Android开发工程师1-6年的人员、正处于瓶颈期,想要年后突破自己涨薪的,进阶Android中高级、架构师对你更是如鱼得水!

为什么某些人会一直比你优秀,是因为他本身就很优秀还一直在持续努力变得更优秀,而你是不是还在满足于现状内心在窃喜!

Android架构师之路很漫长,一起共勉吧!

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

现状内心在窃喜!

Android架构师之路很漫长,一起共勉吧!

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

  • 28
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值