如何以编程方式禁用 Android 上的状态栏/通知栏?

发布于 2024-12-06 18:22:05 字数 217 浏览 1 评论 0原文

我创建一个锁屏应用程序。该应用程序由短信触发。当收到包含命令的短信时,它将显示锁屏活动。

我的锁屏活动正在使用 TYPE_KEYGUARD 禁用主屏幕按钮。当设备屏幕关闭然后我再次打开它时,我的问题是状态栏/通知栏仍然出现在我的屏幕上。这是一个问题,因为即使设备被锁定,用户仍然可以通过状态栏/通知栏访问某些程序。所以我想消失这个状态栏/通知栏,以便用户(盗窃)无法再访问该设备。 请帮我解决这个问题..

i create a lockscreen application.. this application is triggered by SMS.. when a SMS containing command was received, it will display a lock screen activity.

my lockscreen activity is using TYPE_KEYGUARD for disabling a home screen button. When device screen turn off and then i turn it on again, my problem is status bar / notification bar still appear on my screen. this is a problem because the user still can access some program through status bar / notification bar even the device is being locked. so i want to dissapear this status bar / notification bar so that the user (theft) can't access that device anymore..
Please help me to solve this..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

二货你真萌 2024-12-13 18:22:05

我认为您想要做的是以编程方式将活动设置为全屏。如果是这样,请考虑以下事项:

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

来源:http://www.androidsnippets。 com/how-to-make-an-activity-fullscreen

I think what you're trying to do is programmatically set an activity as fullscreen. If so, consider the following:

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

Source: http://www.androidsnippets.com/how-to-make-an-activity-fullscreen

给我一枪 2024-12-13 18:22:05
  public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
      getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}
  public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
      getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}
无声静候 2024-12-13 18:22:05
requestWindowFeature(Window.FEATURE_NO_TITLE);

仅禁用活动的标题栏,而不禁用顶部的通知栏。

在 Android 清单中使用此主题进行您的​​活动:

"Theme.NoTitleBar.Fullscreen"

对我有用。

它隐藏了通知栏。

requestWindowFeature(Window.FEATURE_NO_TITLE);

only disables the activity's title bar, not the notification bar at the top.

Use this theme in android manifest for your activity :

"Theme.NoTitleBar.Fullscreen"

did work for me.

It hides the notification bar.

愛放△進行李 2024-12-13 18:22:05

在 Android 4.0 及更低版本上

选项 1:

<application
    ...
    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
    ...
</application>

选项 2:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // If the Android version is lower than Jellybean, use this call to hide
        // the status bar.
        if (Build.VERSION.SDK_INT < 16) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        setContentView(R.layout.activity_main);
    }
    ...
}

在 Android 4.1 及更高版本上

View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();

对于 Android 4.6(Api 19) 及更高版本,请使用沉浸式全屏
模式

来自 Google 的参考

On Android 4.0 and lower

Option 1:

<application
    ...
    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
    ...
</application>

Option 2:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // If the Android version is lower than Jellybean, use this call to hide
        // the status bar.
        if (Build.VERSION.SDK_INT < 16) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        setContentView(R.layout.activity_main);
    }
    ...
}

on Android 4.1 and Higher

View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();

And for Android 4.6(Api 19) and higher use the Immersive Full-Screen
Mode

Reference from Google

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文