動態設置全屏、取消全屏的方法,以及切換全屏保持內容位置不變的方法

http://blog.csdn.net/lovehong0306
佈局


有兩種形式設置、取消全屏的方法,之因此稱做兩種形式而不是兩種方法,是由於這兩種方式只是寫法不一樣,實質是同樣的。spa


形式一:.net

//設置全屏orm

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
blog

//取消全屏get

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
it


形式二:方法

//設置全屏margin

WindowManager.LayoutParams attr = getWindow().getAttributes();
attr.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attr);
top

//取消全屏

WindowManager.LayoutParams attr = getWindow().getAttributes();
attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(attr);



全屏狀態改成非全屏保持內容位置不變:
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);


這裏有一個問題:

當設置了該flag以後取消全屏,部份內容被狀態欄擋住(忽略狀態欄高度,以屏幕右上角爲原點計算佈局)

加上代碼getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);能夠解決該問題,但再次設置全屏的時候狀態欄不消失。

目前該問題還沒有想到好的解決方案,

若是誰有思路解決了該問題,歡迎提供給我。


http://blog.csdn.net/lovehong0306

相關文章
相關標籤/搜索