How to hide bottom system bar in android tablet

不问归期 提交于 2020-01-13 10:25:50

问题


I am developing an application for tablet only, where the requirement is to run the app on the full screen of the tablet.

For this I have used following code in my main activity:

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

This code snippet only removes the title bar and action bar. But in tablets, there is a bottom system bar (having home and back button). I also want to remove or hide this system bar too.

I have searched but there is only following solution:

  1. There is no API to remove or hide the system bar.
  2. You can use some android app to hide system bar. (for example: surelock, hidebar, etc)

My question is :

  1. Is it really not possible in android?
  2. Above available app (i.e surelock, hide bar, etc) also hiding bar. It means they are using something to do so. Can be use this something in our app so the user will not require to download these app seperatly.

Please guide me.

I know this is not a good idea. But My app is only for tablet having Android 4.0 or greater and that tablet will run only this single app so we do not need to go back and use home button. That's why my requirement is to use the app in full screen.


回答1:


If you have root access you can use this code other wise it is not allowed

try{
    //REQUIRES ROOT
    Build.VERSION_CODES vc = new Build.VERSION_CODES();
    Build.VERSION vr = new Build.VERSION();
    String ProcID = "79"; //HONEYCOMB AND OLDER

    //v.RELEASE  //4.0.3
    if(vr.SDK_INT >= vc.ICE_CREAM_SANDWICH){
        ProcID = "42"; //ICS AND NEWER
    }



    //REQUIRES ROOT
    Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity "+ ProcID +" s16 com.android.systemui"}); //WAS 79
    proc.waitFor();

}catch(Exception ex){
    Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}

See this




回答2:


From Android API 4.0 and later you can use the following code to hide the bottom system bar.

View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
          | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);



回答3:


This is not possible unless you've root access. Alternatively, you can create a launcher application.

Otherwise it will be beyond the scope of your Application to Hide System/Navigation bar.




回答4:


After a lot of searching on the internet, I managed to get the System Bar to hide and appear in a 4.2 device using:

To Hide:

Runtime.getRuntime().exec("service call activity 42 s16 com.android.systemui");

Or use 79 instead of 42 for API less than 14. You may also need to include the SET_DEBUG_APP permission, in which case you need to have the application signed with the system key or installed in the /system/app/ directory.

To Show:

Runtime.getRuntime().exec("am startservice --user 0 -n com.android.systemui/.SystemUIService");

Alternatively some people have used the -a (instead of -n) option, though this was causing an error on my device:

Error: Not found; no service started.



来源:https://stackoverflow.com/questions/16057096/how-to-hide-bottom-system-bar-in-android-tablet

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