I'm trying to make an application full screen (for all activations). Created an abstract FullscreenActivity and inherit the rest from it.

public abstract class FullscreenActivity extends AppCompatActivity { @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { hideSystemUI(); } } private void hideSystemUI() { View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); } private void showSystemUI() { View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } } 

The following problems occurred:

  1. When you change the activation briefly, ActionBar and NavigationBar appear and disappear (flashes);
  2. When you download the application, ActionBar and NavigationBar are instantly visible (flashes).

How to fix this? And in general, did I choose the right method with class inheritance?

I try to implement through the theme in the manifest

 <style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar"> <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> <item name="android:windowFullscreen">true</item> <item name="android:windowContentOverlay">@null</item> </style> 

But it does not go out to hide NavigationBar

  • I would advise you to correct the title, it is not very clear when changing what should be FullScreen - Andrew Goroshko

1 answer 1

You can make an abstract class like this should help:

 public class ActivityName extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // remove title requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); } } 

Or you can do it through your AndroidManifest.xml file:

 <activity android:name=".ActivityName" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/> 

If you use AppCompatActivity , you need to set a theme, as shown below.

 <activity android:name=".ActivityName" android:label="@string/app_name" android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> 

Original: https://stackoverflow.com/a/2868052

  • Almost came out, but the problem with the navigation bar remained, I added in the question - Maxim Zheleznyakov
  • one
    Transferred the code to hide NagivationBar in onResume and everything turned out - Maxim Zheleznyakov
  • write some crutches ... - Flippy
  • Create a theme without bars and put in the manifest. nothing should flash since the android before rendering already knows that the activation will be in fullscreen - Flippy
  • without an action bar, it turned out, but I did not find a way to remove the navigation bar (updated question) - Maxim Zheleznyakov