首先,我们先在values下的style中加入如下代码:
<!-- 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>
<item name="android:windowTranslucentStatus">true</item></style>//可写可不写 <style name="AppTheme.Main" parent="AppTheme" />
//沉浸式主要是加拉
<item name="android:windowTranslucentStatus">true</item>
//隐藏项目标题的代码是
把parent="Theme.AppCompat.Light.DarkActionBar"改为parent="Theme.AppCompat.Light.NoActionBar"
//通过代码实现
public void chenjishi(boolean flog){ if(flog){ if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT){ getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } } }