推荐方法:在自定义的styles中设置隐藏状态栏和标题栏的theme,并在AndroidManifest.xml文件中的application或某个activity中设置。

styles文件如下


[html]  view plain  copy

    1. <resources>  
    2.   
    3. <!-- Base application theme. -->  
    4. <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">  
    5. <!-- Customize your theme here. -->  
    6. <item name="colorPrimary">@color/colorPrimary</item>  
    7. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>  
    8. <item name="colorAccent">@color/colorAccent</item>  
    9. </style>  
    10.   
    11. <style name="AppTheme.NoBar">  
    12. <item name="windowNoTitle">true</item>  
    13. <item name="android:windowFullscreen">true</item>  
    14. </style>  
    15.   
    16. </resources>


    AndroidManifest.xml文件如下:

    [html]  view plain  copy

    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
    3. package="com.jianchi.fsp.myapplication">  
    4.   
    5. <application  
    6. android:allowBackup="true"  
    7. android:icon="@mipmap/ic_launcher"  
    8. android:label="@string/app_name"  
    9. android:supportsRtl="true"  
    10. android:theme="@style/AppTheme">  
    11. <activity android:name=".MainActivity" android:theme="@style/AppTheme.NoBar">  
    12. <intent-filter>  
    13. <action android:name="android.intent.action.MAIN" />  
    14. <category android:name="android.intent.category.LAUNCHER" />  
    15. </intent-filter>  
    16. </activity>  
    17. </application>  
    18.   
    19. </manifest>