方法一

[java] view plain copy
  1. publicclassMainActivityextendsActivity
  2. {
  3. @Override
  4. protectedvoidonCreate(BundlesavedInstanceState)
  5. {
  6. super.onCreate(savedInstanceState);
  7. //隐藏标题栏
  8. requestWindowFeature(Window.FEATURE_NO_TITLE);
  9. //隐藏状态栏
  10. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  11. WindowManager.LayoutParams.FLAG_FULLSCREEN);
  12. setContentView(R.layout.activity_main);
  13. }
  14. }
方法二 [html] view plain copy
  1. <!--同时隐藏状态栏和标题栏-->
  2. <activity
  3. android:name="com.ysj.demo.MainActivity"
  4. android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
  5. android:label="@string/app_name">
  6. <intent-filter>
  7. <actionandroid:name="android.intent.action.MAIN"/>
  8. <categoryandroid:name="android.intent.category.LAUNCHER"/>
  9. </intent-filter>
  10. </activity>
方法三 [html] view plain copy
  1. <!--Applicationtheme.-->
  2. <stylename="AppTheme"parent="AppBaseTheme">
  3. <!--AllcustomizationsthatareNOTspecifictoaparticularAPI-levelcangohere.-->
  4. <!--隐藏状态栏-->
  5. <itemname="android:windowFullscreen">true</item>
  6. <!--隐藏标题栏-->
  7. <itemname="android:windowNoTitle">true</item>
  8. </style>

注:

1、方法一中的两段代码要在setContentView()之前。

2、方法二只能同时隐藏状态栏和标题栏。

3、方法一和方法二都只应用于单个Activity。方法三应用于整个程序。

对于运行Android 4.0以上系统的平板电脑,以上三种方法都不会隐藏屏幕下方的状态栏,须做如下处理。

[java] view plain copy
  1. publicclassStartupActivityextendsActivity
  2. {
  3. @Override
  4. protectedvoidonCreate(BundlesavedInstanceState)
  5. {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_startup);
  8. /*
  9. *隐藏运行Android4.0以上系统的平板的屏幕下方的状态栏
  10. */
  11. try
  12. {
  13. StringProcID="79";
  14. if(android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH)ProcID="42";//ICS
  15. //需要root权限
  16. Processproc=Runtime.getRuntime().exec(newString[]{"su","-c","servicecallactivity"+ProcID+"s16com.android.systemui"});//WAS
  17. proc.waitFor();
  18. }
  19. catch(Exceptionex)
  20. {
  21. Toast.makeText(getApplicationContext(),ex.getMessage(),Toast.LENGTH_LONG).show();
  22. }
  23. }
  24. @Override
  25. protectedvoidonDestroy()
  26. {
  27. //TODOAuto-generatedmethodstub
  28. /*
  29. *恢复运行Android4.0以上系统的平板的屏幕下方的状态栏
  30. */
  31. try
  32. {
  33. Processproc=Runtime.getRuntime().exec(newString[]{"am","startservice","-n","com.android.systemui/.SystemUIService"});
  34. proc.waitFor();
  35. }
  36. catch(Exceptione)
  37. {
  38. e.printStackTrace();
  39. }
  40. super.onDestroy();
  41. }
  42. @Override
  43. publicbooleanonCreateOptionsMenu(Menumenu)
  44. {
  45. //Inflatethemenu;thisaddsitemstotheactionbarifitispresent.
  46. getMenuInflater().inflate(R.menu.startup,menu);
  47. returntrue;
  48. }
  49. @Override
  50. publicbooleanonOptionsItemSelected(MenuItemitem)
  51. {
  52. //TODOAuto-generatedmethodstub
  53. switch(item.getItemId())
  54. {
  55. caseR.id.action_exit:
  56. finish();
  57. break;
  58. }
  59. returntrue;
  60. }
  61. }
由于没有了状态栏,须在程序中提供退出程序的方法。

更多相关文章

  1. Android中JNI高级应用 - 本地C代码中创建Java对象及本地JNI对象
  2. 动态权限
  3. android中获取string字符串的方法
  4. Android屏幕100%适配方案
  5. java.lang.IllegalStateException Fragment already added: Home
  6. android软件盘的开关
  7. Android面试-Android部分
  8. Android(安卓)MediaPlayer使用方法简单介绍
  9. Android(安卓)将Uri转换成File

随机推荐

  1. Android开发资源完全汇总(转MatthewChen
  2. android android屏幕禁止休眠和锁屏的方
  3. use '@foo' to launch a virtual device
  4. 深入浅出 - Android系统移植与平台开发(七
  5. Android(安卓)Drawable Resource学习(一)、
  6. 【Unity3D】与Android相互传递消息
  7. android中的recovery模式
  8. Application Fundamentals
  9. android测试
  10. android自制的软件如何添加到打开方式