full screen application android

被刻印的时光 ゝ 提交于 2019-11-27 22:16:21

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)

-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.

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);

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);

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)
        {
        }

}

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 !

Vijaysachin

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.

go to your manifest and add this to your activity

<activity
        android:name="yourPackage.yourActivity"

        android:theme="@android:style/Theme.Black.NoTitleBar">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!