full screen application android
Asked Answered
L

8

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.

Like answered 29/8, 2013 at 13:43 Comment(5)
Isn't your app running in full screen when where is no notification bar?!Roath
You may look at using setSystemUIVisibility(int) and the various flags to use such as SYSTEM_UI_FLAG_LOW_PROFILE You can use different flags in conjunction with each other by separating them with |Richman
@Like ,did you find your answer?Pes
not yet majid golshadiLike
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 activityInsolent
A
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)

Ayah answered 31/8, 2013 at 2:13 Comment(4)
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 flagsCraigie
it doesn't work in my case,it just make it low profile @chrkadLike
Don't you have to re-call the setSystemUiVisibility() method every time Activity.onWindowFocusChanged(true) is called?Racquelracquet
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().Git
M
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.
Margueritamarguerite answered 2/10, 2014 at 12:39 Comment(2)
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!Like
@Like 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.Margueritamarguerite
M
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);
Malcommalcontent answered 8/2, 2014 at 19:18 Comment(3)
i want this in jellybeans 4.1 not the kitkatLike
ok sorry i understand this don't know to help you here maybe a combination of the other flags is good enough?Malcommalcontent
check this #9559138Malcommalcontent
R
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);
Rapine answered 29/8, 2013 at 14:13 Comment(0)
C
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)
        {
        }

}
Carioca answered 29/8, 2013 at 15:35 Comment(0)
I
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 !

Itin answered 29/8, 2013 at 16:50 Comment(1)
To prevent jerkiness between 2 full screen activities (with hidden navigation bar), call setSystemUiVisibility() before setContentView() in onCreate();Racquelracquet
B
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.

Brunk answered 4/9, 2015 at 7:16 Comment(0)
R
-2

go to your manifest and add this to your activity

<activity
        android:name="yourPackage.yourActivity"

        android:theme="@android:style/Theme.Black.NoTitleBar">
Rapine answered 30/9, 2013 at 19:55 Comment(1)
".Fullscreen" is missing after "NoTitleBar"Cahoot

© 2022 - 2024 — McMap. All rights reserved.