Recently Added

6/recent/ticker-posts

Hide and Show status, navigation and video controls Video Player App Part 11

On this page, I am going to show you how you can hide the status bar navigation bar and video controls with a click
So let's start



1.Create Some Reference Variable in VideoPlayer.java

RelativeLayout zoomLayout;
boolean isOpen = true;



2.Assign the Variable and setOnClickListener
zoomLayout = findViewById(R.id.zoom_layout);
zoomLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isOpen){
hideDefaultControls();
isOpen = false;
}else {
showDefaultControls();
isOpen = true;
}
}
});

3.Create hideDefaultControls(); and showDefaultControls();



private void hideDefaultControls(){
one.setVisibility(View.GONE);
two.setVisibility(View.GONE);
three.setVisibility(View.GONE);
four.setVisibility(View.GONE);
//Todo this function will hide status and navigation when we click on screen
final Window window = this.getWindow();
if (window == null){
return;
}
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
final View decorView = window.getDecorView();
if (decorView!=null){
int uiOption = decorView.getSystemUiVisibility();
if (Build.VERSION.SDK_INT >= 14) {
uiOption |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
}
if (Build.VERSION.SDK_INT >= 16) {
uiOption |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
if (Build.VERSION.SDK_INT >= 19) {
uiOption |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
decorView.setSystemUiVisibility(uiOption);
}
}

private void showDefaultControls(){
one.setVisibility(View.VISIBLE);
two.setVisibility(View.VISIBLE);
three.setVisibility(View.VISIBLE);
four.setVisibility(View.VISIBLE);
//todo this function will show status and navigation when we click on screen
final Window window = this.getWindow();
if (window == null){
return;
}
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
final View decorView = window.getDecorView();
if (decorView!=null){
int uiOption = decorView.getSystemUiVisibility();
if (Build.VERSION.SDK_INT >= 14) {
uiOption &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
}
if (Build.VERSION.SDK_INT >= 16) {
uiOption &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
if (Build.VERSION.SDK_INT >= 19) {
uiOption &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
decorView.setSystemUiVisibility(uiOption);
}
}

 Watch the full Tutorials

Post a Comment

0 Comments