如何禁用 android 中的状态栏?
我想在活动中禁用状态栏,我使用下面的代码,它发生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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您需要从 java 代码中禁用状态栏,那么您可以这样做:
IF you need to disable the status bar from your java code, then you can do this:
简单的解决方案,只需将
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” 添加到您的清单中,例如:
Simple solution, just add
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”
to your manifest, for example: