我希望在活动中禁用状态栏,我使用下面的代码,它发生SecurityException,
StatusBarManagerService:用户10049和当前进程都没有android.permission.STATUS_BAR。我添加<uses-permission android:name="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();
}
}
}
}
}
答案 0 :(得分:3)
如果您需要从java代码中禁用状态栏,则可以执行以下操作:
Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
答案 1 :(得分:2)
简单的解决方案,只需将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>