在清单文件中:
android:screenOrientation=
"landscape"是限制此页面横屏显示,
android:screenOrientation=
"portrait"是限制此页面数竖屏显示。
"unspecified"
- 默認值. 由系統選擇顯示方向. 在不同的設備可能會有所不同.
"landscape"
- 橫向
"portrait"
- 縱向
"user"
- 用戶當前的首選方向
"behind"
- 與在活動堆棧下的活動相同方向
"sensor"
- 根據物理方向傳感器確定方向. 取決於用戶手持的方向, 當用戶轉動設備, 它跟隨改變.
"nosensor"
- 不經物理方向傳感器確定方向. 該傳感器被忽略, 所以當用戶轉動設備, 顯示不會跟隨改變. 除了這個區別,系統選擇使用相同的政策取向對於“未指定”設置. 系統根據“未指定”(
"unspecified")設定選擇相同顯示方向.
android:screenOrientation=
[
"unspecified" |
"behind" |
"landscape" |
"portrait"|
"reverseLandscape"|
"reversePortrait" |
"sensorLandscape" |
"sensorPortrait" |
"userLandscape" |
"userPortrait" |
"sensor" |
"fullSensor" |
"nosensor" |
"user" |
"fullUser" |
"locked"]
其中sensorLandscape就是横屏根据重力切换,sensorPortrait竖屏根据重力切换。
如果要使Activity的View界面全屏,只需要将最上面的信号栏和Activity的Title栏隐藏掉即可,隐藏Title栏的代码:
requestWindowFeature(Window
.FEATURE_NO_TITLE)
配置文件里代码:
android:theme=
"@android:style/Theme.NoTitleBar"
隐藏信号栏的代码:
getWindow()
.setFlags(WindowManager
.LayoutParams.FLAG_FULLSCREEN, WindowManager
.LayoutParams.FLAG_FULLSCREEN)
其它使用:
getWindow()
.setFlags(WindowManager
.LayoutParams.TYPE_STATUS_BAR, WindowManager
.LayoutParams.TYPE_STATUS_BAR)
通常我们的应用只会设计成横屏或者竖屏,锁定横屏或竖屏的方法是在manifest
.xml文件中设定属性Android:screenOrientation为”landscape”或”portrait”:
<activity
android:name=
"com.jooylife.jimei_tablet.base.Main"
android:label=
"@string/app_name"
android:screenOrientation=
"landscape">
<intent-filter>
<action android:name=
"android.intent.action.MAIN" />
<category android:name=
"android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
其实screenOrientation还可以设置成很多值:
android:screenOrientation=
[
"unspecified" |
"behind" |
"landscape" |
"portrait"|
"reverseLandscape"|
"reversePortrait" |
"sensorLandscape" |
"sensorPortrait" |
"userLandscape" |
"userPortrait" |
"sensor" |
"fullSensor" |
"nosensor" |
"user" |
"fullUser" |
"locked"]
其中sensorLandscape就是横屏根据重力切换,sensorPortrait竖屏根据重力切换。
播放视频全屏切换:
1.Demo:
@Override
protected void onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState)
setContentView(R
.layout.activity_main)
if(this
.getResources()
.getConfiguration()
.orientation==Configuration
.ORIENTATION_LANDSCAPE) {
getWindow()
.getDecorView()
.setSystemUiVisibility(View
.INVISIBLE)
}else if (this
.getResources()
.getConfiguration()
.orientation==Configuration
.ORIENTATION_PORTRAIT) {
// this
.requestWindowFeature(Window
.f)
// this
.getWindow()
.setFlags(WindowManager
.LayoutParams.FLAG_FULLSCREEN,
// WindowManager
.LayoutParams.FLAG_FULLSCREEN)
Log
.i(“info”, “portrait”)
}
View类提供了setSystemUiVisibility和getSystemUiVisibility方法,这两个方法实现对状态栏的动态显示或隐藏的操作,以及获取状态栏当前可见性。
setSystemUiVisibility(int visibility)方法可传入的实参为:
1. View
.SYSTEM_UI_FLAG_VISIBLE:显示状态栏,Activity不全屏显示(恢复到有状态的正常情况)。
2. View
.INVISIBLE:隐藏状态栏,同时Activity会伸展全屏显示。
3. View
.SYSTEM_UI_FLAG_FULLSCREEN:Activity全屏显示,且状态栏被隐藏覆盖掉。
4. View
.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:Activity全屏显示,但状态栏不会被隐藏覆盖,状态栏依然可见,Activity顶端布局部分会被状态遮住。
5. View
.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION:效果同View
.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
6. View
.SYSTEM_UI_LAYOUT_FLAGS:效果同View
.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
7. View
.SYSTEM_UI_FLAG_HIDE_NAVIGATION:隐藏虚拟按键(导航栏)。有些手机会用虚拟按键来代替物理按键。
8. View
.SYSTEM_UI_FLAG_LOW_PROFILE:状态栏显示处于低能显示状态(low profile模式),状态栏上一些图标显示会被隐藏。
2.
if (this
.getResources()
.getConfiguration()
.orientation == Configuration
.ORIENTATION_LANDSCAPE) {
WindowManager
.LayoutParams attrs = getWindow()
.getAttributes()
attrs
.flags |= WindowManager
.LayoutParams.FLAG_FULLSCREEN
getWindow()
.setAttributes(attrs)
getWindow()
.addFlags(
WindowManager
.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
} else if (this
.getResources()
.getConfiguration()
.orientation == Configuration
.ORIENTATION_PORTRAIT) {
WindowManager
.LayoutParams attrs = getWindow()
.getAttributes()
attrs
.flags &= (~WindowManager
.LayoutParams.FLAG_FULLSCREEN)
getWindow()
.setAttributes(attrs)
getWindow()
.clearFlags(
WindowManager
.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
转载请注明原文地址: https://ju.6miu.com/read-39210.html