博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android平板开发永久实现全屏的方法
阅读量:6890 次
发布时间:2019-06-27

本文共 3585 字,大约阅读时间需要 11 分钟。

hot3.png

似乎Android4.x.x好像要手动授权,其他的Android系统就不太清楚了  //实现让状态栏恢复 public static void showBar() {        try {            String command;            command = "LD_LIBRARY_PATH=endorb:/systemb am startservice -n com.android.systemui/.SystemUIService";            ArrayList
envlist = new ArrayList
(); Map
env = System.getenv(); for (String envName : env.keySet()) { envlist.add(envName + "=" + env.get(envName)); } String[] envp = envlist.toArray(new String[0]); Process proc = Runtime.getRuntime().exec( new String[]{"su", "-c", command}, envp); proc.waitFor(); } catch (Exception e) { e.printStackTrace(); } }}
//隐藏状态栏实现全屏public static void closeBar() {    try {        String command;        command = "LD_LIBRARY_PATH=endorb:/systemb service call activity 42 s16 com.android.systemui";        ArrayList
envlist = new ArrayList
(); Map
env = System.getenv(); for (String envName : env.keySet()) { envlist.add(envName + "=" + env.get(envName)); } String[] envp = envlist.toArray(new String[0]); Process proc = Runtime.getRuntime().exec( new String[]{"su", "-c", command}, envp); proc.waitFor(); } catch (Exception ex) { ex.printStackTrace(); }}

上面的在android4.4上面只需要点击获取权限即可实现要求,而在android5.1上面就不行。下面提供一种比上面更好的方法:

public void toggleHideyBar() {        // BEGIN_INCLUDE (get_current_ui_flags)          // The UI options currently enabled are represented by a bitfield.          // getSystemUiVisibility() gives us that bitfield.          int uiOptions = getWindow().getDecorView().getSystemUiVisibility();        int newUiOptions = uiOptions;        // END_INCLUDE (get_current_ui_flags)          // BEGIN_INCLUDE (toggle_ui_flags)          boolean isImmersiveModeEnabled =                ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);        if (isImmersiveModeEnabled) {            Log.i("123", "Turning immersive mode mode off. ");        } else {            Log.i("123", "Turning immersive mode mode on.");        }        // Navigation bar hiding:  Backwards compatible to ICS.          if (Build.VERSION.SDK_INT >= 14) {            newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;        }        // Status bar hiding: Backwards compatible to Jellybean          if (Build.VERSION.SDK_INT >= 16) {            newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;        }        // Immersive mode: Backward compatible to KitKat.          // Note that this flag doesn't do anything by itself, it only augments the behavior          // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample          // all three flags are being toggled together.          // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".          // Sticky immersive mode differs in that it makes the navigation and status bars          // semi-transparent, and the UI flag does not get cleared when the user interacts with          // the screen.          if (Build.VERSION.SDK_INT >= 18) {            newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;        }       //getWindow().getDecorView().setSystemUiVisibility(newUiOptions);//上边状态栏和底部状态栏滑动都可以调出状态栏          getWindow().getDecorView().setSystemUiVisibility(4108);//这里的4108可防止从底部滑动调出底部导航栏          //END_INCLUDE (set_ui_flags)      }

 

 

 

转载于:https://my.oschina.net/u/2987490/blog/822349

你可能感兴趣的文章
服务器监控客户端系统状态4.0
查看>>
zz STL系列之十 全排列(百度迅雷笔试题)
查看>>
python --- 面向对象编程
查看>>
TensorFlow --- 01初识
查看>>
shell编程-变量
查看>>
[转帖]c头文件(.h)的作用
查看>>
中文乱码问题解决方法总结
查看>>
渗透测试
查看>>
详解如何使用Docker Hub官方的MySQL镜像生成容器
查看>>
Perl 输出颜色
查看>>
docker疑难解答 -- 设置远程服务监听
查看>>
mysql grant 用户权限总结
查看>>
python实现简单登陆流程
查看>>
二级域名和二级目录在SEO中的区别(二)
查看>>
设计并实施CRM与ERP的整合方案
查看>>
将无限循环小数化为分数
查看>>
MetaMask/metamask-extension/mascara 的运行实现
查看>>
loglevel-metamask
查看>>
决策树算法实现(train+test,matlab) 转
查看>>
51Nod-1126 求递推序列的第N项【递推序列+模除】
查看>>