Android的沉浸式

一、效果图

沉浸式.gif

二、代码实现

1.在styles.xml下新建一个style

<style name="TranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  <item name="android:windowTranslucentStatus">false</item>
  <item name="android:windowTranslucentNavigation">true</item>
  <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
  <item name="android:statusBarColor">@android:color/transparent</item>
</style>

2.在AndroidManifest.xml的activity标签下加入上述style

<activity android:name=".MainActivity"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustPan"
    android:launchMode="singleTask"
    android:theme="@style/TranslucentTheme"/>

3.在Activity的布局文件的根布局上加入android:fitsSystemWindows="true"

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:layout_height="match_parent"
    android:background="@drawable/bg_splash">
    ...
</LinearLayout>

另外需要注意的是:沉浸式状态栏只支持安卓4.4及以上的版本

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容