13

i have two questions:

  1. one how can i run my application in full screen
  2. how video players run videos in full screen.

i have tried alot and still struggling to achieve this but couldn't find a solution.

the list of solution i found but they are not fulfilling my requirements

  • this hides only the notification bar.

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

  • also hides only the notification bar

    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    
  • it low profiles the navigation bar not hiding it.

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

  • no effect on my activity.

    anyView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

note that:

  • i am not talking about rooting a device,so please provide those solutions which can work without rooting a device.
  • i am not talking about hiding only notification bar,but full screen by hiding both navigation bar and notification bar too.
  • i am talking about jelly beans api 4.1 or greater than 4.1 version of android
  • and please give answers with code.

after my research and your answers, i am getting this:

enter image description here

but my app should look like this without navigation bar:

enter image description here

i do not want the system navigation bar visible in my app.

Hamad
  • 5,096
  • 13
  • 37
  • 65
  • Isn't your app running in full screen when where is no notification bar?! – Enthusiasmus Aug 29 '13 at 13:46
  • You may look at using `setSystemUIVisibility(int)` and the various flags to use such as [SYSTEM_UI_FLAG_LOW_PROFILE](http://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_LOW_PROFILE) You can use different flags in conjunction with each other by separating them with `|` – codeMagic Aug 29 '13 at 14:43
  • @Hamad ,did you find your answer? – Majid Golshadi Feb 15 '14 at 14:57
  • not yet majid golshadi – Hamad Feb 15 '14 at 16:34
  • Is there a way to hide the system navigation bar during startup of my app when the splash screen is being displayed ? At that point, the OnCreateView() of the Activity hasn't been called yet. All that is displayed is coming from my theme settings for the activity – The Mitra Boy May 25 '16 at 07:50

8 Answers8

30

I'm not sure what you're after, but the following hides the Notification bar, and the Soft Navigation keys (as seen on Google Nexus-devices), so the app essentially is "full screen".

Edit2

In Android 4.4 (API 19) Google introduced the new Immersive mode which can hide the status & navbar and allow for a truly fullscreen UI.

// This snippet hides the system bars.
private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    mDecorView.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 // hide nav bar
              | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
              | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    mDecorView.setSystemUiVisibility(
               View.SYSTEM_UI_FLAG_LAYOUT_STABLE
             | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
             | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

Reference:
https://developer.android.com/training/system-ui/immersive.html

Edit:
Tested on Android 4.3 (API 18) and Android 4.1 (API 16) with Soft Nav keys.

@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);

    setContentView(R.layout.main);

    int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LOW_PROFILE
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

    getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
}

For more information read up on http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)

kaderud
  • 5,457
  • 2
  • 36
  • 49
  • Lol never mind the down votes :D For KitKat or above use this single line code in onCreate - getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); Fos os version below KitKat(API 19) - Use the other flags – Arun Jose Dec 05 '13 at 10:02
  • it doesn't work in my case,it just make it low profile @chrkad – Hamad Jan 15 '14 at 09:53
  • 1
    Don't you have to re-call the setSystemUiVisibility() method every time Activity.onWindowFocusChanged(true) is called? – mmathieum Mar 13 '14 at 15:27
  • Where you set the UI flags makes a difference. If you hide the system bars in your activity's onCreate() method and the user presses Home, the system bars will reappear. When the user reopens the activity, onCreate() won't get called, so the system bars will remain visible. If you want system UI changes to persist as the user navigates in and out of your activity, set UI flags in onResume() or onWindowFocusChanged(). – Eftekhari Jun 04 '16 at 23:02
2

-To hide Status bar:

A great solution I found for that issue, setting each Activity theme & windowSoftInputMode to the following values :

<activity   android:name=".MyActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
            android:windowSoftInputMode="adjustResize">  <!-- theme : to set the activity to a full screen mode without a status bar(like in some games) -->
</activity>                                              <!-- windowSoftInputMode : to resize the activity so that it fits the condition of displaying a softkeyboard -->

for more info refer here.

-To hide Notification bar:

There are Two ways :

1- root your device, then open the device in adb window command, and then run the following:

 adb shell >
 su >
 pm disable com.android.systemui >

and to get it back just do the same but change disable to enable.

2- add the following line to the end of your device's build.prop file :

qemu.hw.mainkeys = 1

then to get it back just remove it.

and if you don't know how to edit build.prop file:

  • download EsExplorer on your device and search for build.prop then change it's permissions to read and write, finally add the line.
  • download a specialized build.prop editor app like build.propEditor.
  • or refer to that link.
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
  • this solution needs device root! and it is not possible for me! to go and root or install any other app to client's device! so this doesn't solve my problem! – Hamad Oct 13 '14 at 05:56
  • @Hamad well, thanks for ur reply, but I think you will not find a solution like you want without routing as even in KitKat there is something called immerse but when taping the main_layout they appear then remain for about 3 secs. – Muhammed Refaat Oct 13 '14 at 07:59
1

On the new android 4.4 you should add this line:

View.SYSTEM_UI_FLAG_IMMERSIVE;

So the new working solution atleast on nexus4 4.4.2 is

final int mUIFlag = 
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
              | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
              | View.SYSTEM_UI_FLAG_LOW_PROFILE
              | View.SYSTEM_UI_FLAG_FULLSCREEN
              | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_IMMERSIVE;

Immersive alone won't work though it works when combined with other flags. see documentation for more details. Then you add in the activity the activating of this setup as shown here before (I am just adding for consistency)

getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
sivi
  • 10,654
  • 2
  • 52
  • 51
  • i want this in jellybeans 4.1 not the kitkat – Hamad Feb 09 '14 at 06:16
  • ok sorry i understand this don't know to help you here maybe a combination of the other flags is good enough? – sivi Feb 09 '14 at 14:42
  • check this http://stackoverflow.com/questions/9558638/how-to-code-backward-compatible-new-feature-in-android-sdk – sivi Feb 10 '14 at 22:20
0

I made 2 layouts one for regular size and one for full screen and inside full scrreen I get the devices size and and assign it to video player

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
int w=size.x;
int h=size.y;
videoPlayer.setFixedSize(w, h);
Omid Aminiva
  • 667
  • 5
  • 14
0

I think you cant hide the system bar in android 4.0 > (only in tablets, in phones you should be able to)

What you can do is to hide the icons and to disable some buttons(everyone except home)

You can try this:

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);              

        }

Also for disabling the buttons:

This is for back button:

  public boolean onKeyDown(int keyCode, KeyEvent event) {
    return false;
  }

This for the menu:

@Override
public void onWindowFocusChanged(boolean hasFocus) {

        try
        {
           if(!hasFocus)
           {
                Object service  = getSystemService("statusbar");
                Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
                Method collapse = statusbarManager.getMethod("collapse");
                collapse .setAccessible(true);
                collapse .invoke(service);
           }
        }
        catch(Exception ex)
        {
        }

}
leojg
  • 1,156
  • 3
  • 16
  • 40
0

Video Players run in full screen by setting the

myView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

setFlags() before setContentView(View)

This will show the system bar on any user interaction, just like video players do.

The closest you can get to running your app full screen is by setting in Lights Out mode, the system buttons will appear as dots.

To use the lights out mode just use any view in your activity and call

anyView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

For Hiding the navigation bar use this in your onStart() so that every time you get to that activity it will be in full screen mode.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

I hope this helps !

jaymeht
  • 678
  • 1
  • 8
  • 14
  • To prevent jerkiness between 2 full screen activities (with hidden navigation bar), call `setSystemUiVisibility()` before `setContentView()` in `onCreate()`; – mmathieum Jan 30 '14 at 15:28
0

Android Version: 4.2.2 - Device: Vega Tablet

Android App to Hide Status and System Bar and displaying complete screen I followed these steps.

AndroidManifest.xml

   <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

MainActivity.java

super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(0x10);
setContentView(R.layout.activity_main);

Above code perfectly worked for my app.

Michiel
  • 468
  • 3
  • 23
-2

go to your manifest and add this to your activity

<activity
        android:name="yourPackage.yourActivity"

        android:theme="@android:style/Theme.Black.NoTitleBar">
Omid Aminiva
  • 667
  • 5
  • 14