如何禁用 android 中的状态栏?

发布于 2025-01-03 10:01:03 字数 1324 浏览 2 评论 0原文

我想在活动中禁用状态栏,我使用下面的代码,它发生SecurityException, StatusBarManagerService:用户10049和当前进程都没有android.permission.STATUS_BAR。我添加了 ,但它不起作用?有人知道如何解决这个问题吗?谢谢

mStatusBar = getSystemService("statusbar");

if (mStatusBar != null){
    Log.v("statusbar", "get status bar service "+mStatusBar.getClass());
    Method[] arrayOfMethods;
    Method localMethod;
    arrayOfMethods = mStatusBar.getClass().getMethods();
    for (int i = 0; i < arrayOfMethods.length; i++){
        localMethod = arrayOfMethods[i];
        Log.v("statusbar", "find status bar method "+localMethod);
        if (localMethod.getName().equalsIgnoreCase("collapse")){
//                    mStatusBarCollapseMethod = localMethod;
            } else if (localMethod.getName().equals("disable")){
                try {
                    Log.v("statusbar", "invoke "+mStatusBar+"."+localMethod.getName()+"(1)");
                    localMethod.invoke(mStatusBar, 1);
                    Log.v("statusbar", "disable statusbar");
                } catch (Exception e) {
                    Log.v("statusbar", "disable statusbar excption:"+e.toString());
                    e.printStackTrace();
                }
            }
        }
    }
}

i want disable statusbar in activity, i have use below code, it happen SecurityException,
StatusBarManagerService: Neither user 10049 nor current process has android.permission.STATUS_BAR. I have add <uses-permission android:name="android.permission.STATUS_BAR">, but it's not works? Anyone know how to resolve this problem? Thanks

mStatusBar = getSystemService("statusbar");

if (mStatusBar != null){
    Log.v("statusbar", "get status bar service "+mStatusBar.getClass());
    Method[] arrayOfMethods;
    Method localMethod;
    arrayOfMethods = mStatusBar.getClass().getMethods();
    for (int i = 0; i < arrayOfMethods.length; i++){
        localMethod = arrayOfMethods[i];
        Log.v("statusbar", "find status bar method "+localMethod);
        if (localMethod.getName().equalsIgnoreCase("collapse")){
//                    mStatusBarCollapseMethod = localMethod;
            } else if (localMethod.getName().equals("disable")){
                try {
                    Log.v("statusbar", "invoke "+mStatusBar+"."+localMethod.getName()+"(1)");
                    localMethod.invoke(mStatusBar, 1);
                    Log.v("statusbar", "disable statusbar");
                } catch (Exception e) {
                    Log.v("statusbar", "disable statusbar excption:"+e.toString());
                    e.printStackTrace();
                }
            }
        }
    }
}

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

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

发布评论

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

评论(2

旧时模样 2025-01-10 10:01:03

如果您需要从 java 代码中禁用状态栏,那么您可以这样做:

Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

IF you need to disable the status bar from your java code, then you can do this:

Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
凉月流沐 2025-01-10 10:01:03

简单的解决方案,只需将 android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” 添加到您的清单中,例如:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.vogella.android.temperature"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Convert"
                  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>
    <uses-sdk android:minSdkVersion="9" />

</manifest>

Simple solution, just add android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” to your manifest, for example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.vogella.android.temperature"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Convert"
                  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>
    <uses-sdk android:minSdkVersion="9" />

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