本文实例讲述了Android开发之禁止下拉通知栏的方法。分享给大家供大家参考,具体如下:
1.在AndroidManifest.xml中添加权限
1
2
|
< uses-permission android:name = "android.permission.EXPAND_STATUS_BAR" /> < uses-permission android:name = "android.permission.STATUS_BAR" /> |
2.在相应的activity中添加
1
2
3
4
5
6
7
8
9
10
11
12
13
|
@Override public void onWindowFocusChanged( boolean hasFocus) { // TODO Auto-generated method stub super .onWindowFocusChanged(hasFocus); try { Object service = getSystemService( "statusbar" ); Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" ); Method test = statusbarManager.getMethod( "collapse" ); test.invoke(service); } catch (Exception ex) { ex.printStackTrace(); } } |
希望本文所述对大家Android程序设计有所帮助。