我正在使用此方法隐藏状态栏:
public static void hideStatusBar(Activity activity) {
if (Build.VERSION.SDK_INT < 16) {
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = activity.getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
这很好,但是当我开始播放视频时,我已经注意到状态栏再次可见,在对我的代码进行了一些测试之后,我意识到在添加MediaController之后,状态栏还是可见的。
我如何保持全屏并仍在使用MediaController?
这是我添加MediaController的方式
mMediaController = new MediaController(getContext());
mMediaController.setAnchorView(this);
setMediaController(mMediaController);
<application
...
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
或
View decorView = getWindow().getDecorView(); // Hide the status bar. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); // Remember that you should never show the action bar if the // status bar is hidden, so hide that too if necessary. ActionBar actionBar = getActionBar(); actionBar.hide();
并查看此链接:http://developer.android.com/training/system-ui/status.html和这个链接:How to hide status bar in Android
setOnSystemUiVisibilityChangeListener来解决它,但类似:
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
}
});