目录
经过,今天项目需要去除顶部导航条,查了很多,总结一下就是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

效果图
