android隐藏状态栏显示出来,Android:显示/隐藏状态栏/电源栏

我正在尝试创建一个按钮,我可以隐藏或显示平板电脑上的状态栏。

我已经加入了onCreategetWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

并在按钮显示:

WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs);

隐藏:

WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs);

任何提示/ tipps?

//编辑

我在这里查看了这个提示: http : //android.serverbox.ch/? p = 306并改变了我的代码:

private void hideStatusBar() throws IOException, InterruptedException { Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity 79 s16 com.android.systemui"}); proc.waitFor(); } private void showStatusBar() throws IOException, InterruptedException { Process proc = Runtime.getRuntime().exec(new String[]{"am","startservice","-n","com.android.systemui/.SystemUIService"}); proc.waitFor(); }

因此,如果我点击我的按钮,方法被调用我可以看到发生了什么,因为应用程序正在等待几秒钟。 我也调查了LockCat,发现事情正在发生。

show: http : //pastebin.com/CidTRSTi隐藏: http : //pastebin.com/iPS6Kgbp

您是否在清单中设置了全屏主题?

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

如果没有这个,我认为你不能全屏。

我将使用以下内容添加和删除全屏标志:

// Hide status bar getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Show status bar getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

对于某些人,通过清除FLAG_FULLSCREEN显示状态栏可能不起作用,

这是适用于我的解决方案,( 文档 )( 标记参考 )

隐藏状态栏

// Hide Status Bar if (Build.VERSION.SDK_INT < 16) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { View decorView = getWindow().getDecorView(); // Hide Status Bar. int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); }

显示状态栏

if (Build.VERSION.SDK_INT < 16) { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { View decorView = getWindow().getDecorView(); // Show Status Bar. int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE; decorView.setSystemUiVisibility(uiOptions); }

KitKat中引入的function之一是“ 沉浸模式 ”。 沉浸式模式使用户能够通过滑动显示/隐藏状态栏和导航栏。 要尝试,请单击“切换沉浸式模式”按钮,然后尝试滑入和滑出该栏!

例:

public void toggleHideyBar() { int uiOptions = getActivity().getWindow().getDecorView().getSystemUiVisibility(); int newUiOptions = uiOptions; boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); if (isImmersiveModeEnabled) { Log.i(TAG, "Turning immersive mode mode off. "); } else { Log.i(TAG, "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; } if (Build.VERSION.SDK_INT >= 18) { newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; } getActivity().getWindow().getDecorView().setSystemUiVisibility(newUiOptions); //END_INCLUDE (set_ui_flags) }

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //hide status bar requestWindowFeature( Window.FEATURE_NO_TITLE ); getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN ); setContentView(R.layout.activity_main); }

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值