安卓开发中,经常需要应用去除标题栏,甚至全屏。这里梳理一下,很简单。一般初学者都会!
1、去除标题栏(两种方式)
1、代码里面
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
这句必须在setContentView()前面
2、在清单文件(manifest.xml)里面实
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
上面第二种方法有个类似的做法就是自己定义style,然后进行设置。异曲同工!
2、设置全屏的方法(3种)
第一种
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
第二种
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
第三种
application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/fullscreem"
3、去除标题栏失效的解决方法
上面的去除标题栏的方法在5.0之前都可以用,但是运行在Android 5.0 之后就没效果了。这时候的做法是将原来的parent换成下面这种。
<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>