去掉手机的状态栏:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
去掉手机的标题栏:一共有三种办法
①requestWindowFeature(Window.FEATURE_NO_TITLE);
一定要写在setContentView(R.layout.activity_main);之前,还要在res下values下的style.xml中,将parent改为parent=”Theme.AppCompat.Light.NoActionBar”,就可以了。
缺点:有时候会先出现状态栏,然后在消失,这是因为我们在onCreate方法中写的。
②直接在清单文件中进行修改,
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
将android:theme的属性改为android:theme=”@style/Theme.AppCompat.NoActionBar”,就可以了。但是这么做的话,是将整个应用都去掉标题栏了,有人会问,我只是想让欢迎页是没有标题栏的,其他的页面都是有状态栏的,我该怎么做呢?
如果是上面的这种问题,我们就动态的设置主题并加上第一种的方式联合使用,
setTheme(android.R.style.Theme_Black_NoTitleBar);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
缺点:比第一种方式好一些
③自定义主题的样式
在res下values下的style.xml中,再添加一个style的标签就行了,
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
</style>
然后在清单文件中,使用这个自定义的主题:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
第三种使用的最好,但是比较麻烦!
本人菜鸟一个,有什么不对的地方希望大家指出评论,大神勿喷,希望大家一起学习进步!