简体   繁体   中英

How to disable statusbar in android?

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

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM