搭建直播带货平台,Android Activity旋转屏幕横屏实现全屏
搭建直播带货平台,Android Activity旋转屏幕横屏实现全屏的相关代码
搭建直播带货平台activity在竖屏的时候,顶部会有状态栏,顶部会有ToolBar,现在需求是,旋转屏幕以后,横屏状态下 整个界面是以全屏状态显示,隐藏ToolBar,不显示屏幕最顶部的状态栏
首先,搭建直播带货平台在AndroidManiFest里面设置Activity的属性:
<activity android:name=".MainActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:screenOrientation="sensor" />
然后,搭建直播带货平台在Activity中重写onConfigurationChanged方法,代码如下:
private boolean portrait; @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); portrait = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT; tryFullScreen(!portrait); } private void tryFullScreen(boolean fullScreen) { if (activity instanceof AppCompatActivity) { ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar(); if (supportActionBar != null) { if (fullScreen) { supportActionBar.hide(); } else { supportActionBar.show(); } } } setFullScreen(fullScreen); } private void setFullScreen(boolean fullScreen) { WindowManager.LayoutParams attrs = getWindow().getAttributes(); if (fullScreen) { attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } else { attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } }
这样就能实现自动旋转屏幕,并且全屏的需求了
以上就是搭建直播带货平台,Android Activity旋转屏幕横屏实现全屏的相关代码, 更多内容欢迎关注之后的文章