方式一:編碼方式
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE);//remove title bar 即隱藏標題欄
getSupportActionBar().hide();// 隱藏ActionBar getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//remove notification bar 即全屏 setContentView(R.layout.activity_main); }
方式二:修改AndroidManifest.xml
:
<activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
但是這種方式異動是程序總是崩潰
原因,升級后theme是由appcompat_v7管理
所以這里theme應該采用android:theme=@style/Theme.AppCompat.Light.NoActionBar”,這個只能隱藏ActionBar
如果想連通知欄也隱藏,可在styles.xml中定義如下樣式,然后再在AndroidManifest.xml中的Application或者Activity上使用
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light"> <item name="android:windowNoTitle">true</item>//無標題 <item name="android:windowActionBar">false</item>//無ActionBar <item name="android:windowFullscreen">true</item>//全屏即無通知欄 <item name="android:windowContentOverlay">@null</item>//是否有遮蓋 </style>
——————————————————————————————————————