目錄
經過,今天項目需要去除頂部導航條,查了很多,總結一下就是2種情況
第一種:使用requestWindowFeature(Window.FEATURE_NO_TITLE);,前提要求是必須在Activity下。
但是這個項目,我是使用Fragement,里面有一個方法getSupportFragmentManager();在Activity下無法使用,頭都要禿了
第二種:在styles.xml中將AppTheme里面的參數parent改為Theme.AppCompat.Light.NoActionBar
<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style>
效果圖
----------------------------------------------------------------------------------------------------------------------------------------------------------------
網上還有一種教程在AppCompatActivity下可以使用的方法,但是親測無用
protected void onCreate(Bundle savedInstanceState) { //去掉系統狀態欄 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.maincontainer); initView(); }
在res/value/styles.xml中添加下面的style
<!-- 去除頂部的狀態欄和標題欄--> <style name="NoTitle" parent="Theme.AppCompat.DayNight.NoActionBar"> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> </style>
在AndroidManifest.xml中調用該style
效果圖