1

I knew this question is being asked previously but not getting the accurate solution. I want to hide ActionBar and NavigationBar from my activity in or order to make it full screen. I tried the below code in my Activities OnCreate Method but its showing Action Bar for some fraction of seconds and than making it full screen. In Galaxy S3 (android 4.3), its even more than a second. so how can I make it completely invisible and my activity as full screen completely from the beginning only. I saw many apps running on S3 only, but their is no ActionBar, not even for fraction seconds.

@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_main);

    if (Build.VERSION.SDK_INT < 19) {           
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
         getWindow().getDecorView().setSystemUiVisibility(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
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }

}
Gilsha
  • 14,431
  • 3
  • 32
  • 47
Suneet Agrawal
  • 269
  • 1
  • 17

6 Answers6

2

In AndroidManifest file write

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

in activity tag

and use

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

befor setContentView(R.layout.activity_main);

Aman Rawat
  • 2,625
  • 1
  • 25
  • 40
2

In the onCreate function of your activity add this code before setContentView:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

In AndroidManifest file write

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

If the minimum SDK Version of your application is 19 (KitKat), then you have to add an additional piece of code to your onResume function:

getWindow().getDecorView().setSystemUiVisibility
                    ( 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
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY );
Unihedron
  • 10,902
  • 13
  • 62
  • 72
0

Try android:theme="@android:style/Theme.NoTitleBar.Fullscreen" in the declaration of your Activtiy in your Manifest.

Kevin Gebhardt
  • 368
  • 1
  • 12
0

try this before setContentView

    //Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    //Remove notification bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Rohit Goswami
  • 617
  • 5
  • 17
0

This Android Developer and This Post demonstrates Immersive Full-Screen Mode which allows your app to go full screen.

tltr;

try this snippet which I got from the Android Developer website:

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
          | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

Hopefully I helped!

Community
  • 1
  • 1
Zer0
  • 1,002
  • 1
  • 19
  • 40
0

i think you have to write just

getActionBar().hide(); (Above Api level 11)

or

getSupportActionBar().hide();(Up to Api level 8)

thats it...

Jayesh Khasatiya
  • 2,140
  • 1
  • 14
  • 15